Open jsl303 opened 4 years ago
probably the method runAndWait() as it indicate it should run, speak then wait for few moments
@Mishalovoper, thanks for the suggestion, but it's the same even if I put time.sleep between call.
Which os are you using? Which version of pyttsx3 are you using?
Raspberry Pi 4: 2020-05-27-raspios-buster-full-armhf pyttsx3: 2.88 Bluealsa: 1.4.0
For me it is stucks as well on OSX and it has to do with NSRunLoop
of Foundation, but couldn't find much into it - it seems on the 2nd call it will never call stopper.stop
One dirty workaround is to reset the state of pyttsx3 by reimporting it on every run
import pyttsx3
import importlib
for words in words_to_say:
importlib.reload(pyttsx3)
engine = pyttsx3.init()
engine.save_to_file(words, f'{words}.mp3'))
engine.runAndWait()
@capital-G Thanks dude...I searched for a whole day but i couldn't find a solution to it.Your answer helped me.But i have something more to ask too... After fixing that error i get another error:
Traceback (most recent call last):
File "/home/bo/.local/lib/python3.9/site-packages/pyttsx3/drivers/espeak.py", line 171, in _onSynth
self._proxy.notify('finished-utterance', completed=True)
ReferenceError: weakly-referenced object no longer exists
could you help with this if you ever faced this...Can't find a stackoverflow answer either.
I had the same problem as @Ajay-Singh-Rana . My workaround uses an auxiliary function and that seems to finally do the trick.
import pyttsx3
import importlib
def engine_init ():
importlib.reload(pyttsx3) # Workaround to be avoid pyttsx3 being stuck
engine = pyttsx3.init()
return engine
words_to_say = [ "one", "two", "three" ]
for words in words_to_say:
importlib.reload(pyttsx3)
engine = engine_init()
engine.save_to_file(words, f'{words}.mp3')
engine.runAndWait()
Hi @ruckard, your workaround works for me on MacOS X. I am unsure about the root cause of the issue so would be great if someone could chip in to explain?
The following test hangs after speaking 0.
import pyttsx3
def speak(msg): engine.say(msg) engine.runAndWait()
engine = pyttsx3.init() for i in range(3): speak(str(i))