nateshmbhat / pyttsx3

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
2.09k stars 330 forks source link

Run Loop Already Started: Error While Terminating pyttsx3 engine running on PyQT5 Thread #193

Open FireHead90544 opened 3 years ago

FireHead90544 commented 3 years ago

Hey developers, I am working on a TTS GUI Based Open source program, so far so good I have implemented everything that needs to be there. But I have implemented a funtionality that will allow user to stop the speech in between while it is playing. I am playing the speech by playing it in another thread ( to stop PyQT5 window from freezing ). But as soon as I clicks on stop button it terminates the thread. But when i am clicking on Play again it debugs this error: RuntimeError('event loop already started.'). I tried endLoop(), stop() functions but still it doesn't works. Looks like these two functions doesnt clear up the queue. image This is the error I am facing.

For better reference, watch this video:

https://user-images.githubusercontent.com/55452780/115274809-b1633a00-a15e-11eb-8230-80cb370afba5.mp4

Please reply to this issue, if needs additional details. Hoping to get help asap.

Thanks, ~ Rudransh Joshi

mad-nation commented 2 years ago

bro did u get any solution? i'm also getting the same error. 🥺

FireHead90544 commented 2 years ago

I am sorry but, not atleast until now bro 🥲 I ended up removing the stop functionality. Looks like we gotta switch over to another library, maybe try win32 or something one :') But since this library was simple I wasn't planning about switching :') Lemme know if you find any fix as well, good luck 🤞

mad-nation commented 2 years ago

oh 😢. i have been searching a lot here and there for a while but didn't find any tutorial or blog relating this. sure i will tell u if i get one.

duolabmeng6 commented 1 year ago

I also encountered the same problem and couldn't solve it

import pyttsx3

class 线程_朗读(QThread):
    def __init__(self, text):
        super().__init__()
        self.mutex = QMutex()
        self.text = text
        self.engine = pyttsx3.init()

    def run(self):
        self.mutex.lock()
        self.engine.say(self.text)
        self.engine.runAndWait()
        self.mutex.unlock()
teymuur commented 9 months ago

Guys i have the same issue while using cv2 and threading but it doesnt resolve anyone got a solution?

FireHead90544 commented 9 months ago

No fixes yet. Though I just got an idea, might try this later but you guys can also try. Not sure if it works.

What if we just delete the existing engine and just after stop (i.e, deleting the thread), create a new engine instance. Ik it's just a workaround but that might work.

JosuaMnl commented 4 months ago

Try putting the code below to stop the engine if it's in a looping state.

if engine._inLoop:
    engine.endLoop()