I created a python code that uses speech engine pyttsx3 and I basically want it to pronounce a word
Here is the code:
import pyttsx3
def say_route(bus_route):
#global list_all_bus, engine
global engine
#while True:
# if there is a number in the bus list, it will be true because length of list > 0
#while list_all_bus:
# initialise engine
engine = pyttsx3.init()
print(f"saying bus route: {bus_route}")
# initialisation
voices = engine.getProperty('voices')
engine.setProperty('rate', 150) # adjust speed of talking. 200 default.
engine.setProperty('voice', voices[1].id) # change the voice of the person talking. 0-2
engine.say(f"going to {' '.join(bus_route)}") # seowbk commented for colab
engine.runAndWait()
engine.stop()
# remove the bus number that was said (first in list)
#list_all_bus.pop(0)
#print(f"nlist busses NEW: {list_all_bus}")
full_route = "YISHUN"
full_route = "".join(full_route.split())
say_route(full_route)
Instead of pronouncing the word, it spells it out entirely, which is what I don’t want it to do.
Does anyone know how I can fix it?
2
I’m not sure of the intent, but it looks like the cause.
full_route = "YISHUN"
full_route = "".join(full_route.split())
full_route
is "YISHUN"
before and after this code, then you’re using
' '.join(bus_route)
which is just "YISHUN"
still.
Again, I am unsure of your intent of what these routes are named, but if your goal is to split this string to characters, you can use list(str)
like so:
say_route(list(full_route))