Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyttsx "run" but without "wait"

Tags:

python

pyttsx

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()
like image 407
2 revs Avatar asked Nov 17 '25 04:11

2 revs


1 Answers

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()
like image 62
MST Avatar answered Nov 18 '25 16:11

MST



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!