I'm using pyttsx in my game, but I have encountered a problem - method runAndWait() causes it to stop for a brief period of time to say the queued text. It is a problem, because it messes up my time counting. Is it possible to say a text but without stopping all other activities? Or maybe is there any other text-to-speech converter in python/pygame?
def say(text):
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('rate', 250)
engine.say(text)
engine.runAndWait()
Pyttsx does not have method like runAndNoWait(), but you can run your say(text) function as separate thread to stop blocking your main game thread.
import threading
text = 'Hello world'
threading.Thread(target=say, args=(text,)).start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With