nateshmbhat / pyttsx3

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

OSError 2147221008 on second run of web app #135

Closed JPL1 closed 4 years ago

JPL1 commented 4 years ago

I have a Flask app which picks up an image file(s), uses Tesseract OCR to get the text then converts text to mp3 using pyttsx3.

The first time of running it works fine: saves local .txt file(s) with the image text to a local directory, saves an mp3(s) with the speech file(s) to the same directory.

However, run it again without restarting and the pyttsx3 operation fails with


OSError: [WinError -2147221008] CoInitialize has not been called

Traceback (most recent call last)

    File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python38\Lib\site-packages\pyttsx3\__init__.py", line 20, in init

    eng = _activeEngines[driverName]

    File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python38\Lib\weakref.py", line 131, in __getitem__

    o = self.data[key]()

Removing pyttsx3 from the app solves the error - it's now possible to upload multiple images one after the other without it crashing, so it definitely seems to be pyttsx3 that's causing the glitch.

Solutions tried so far: Used pyttsx3 version 2.71 - app failed with a different coinitialise error Used 32 bit python interpreter - no difference
Used session instead of global variable for the text - no difference

Windows 10 Pro v1903 Browsers tried Edge, Chrome, Opera Python version 3.8.4 64bit pyttsx3 v 2.90 IDE = VS Code

Help appreciated

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.64. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

akchhayalok commented 4 years ago

Try installing sapi5 by

pip install sapi
JPL1 commented 4 years ago

Thank you - I will try. It seems to be very machine specific. I've got it working on another laptop now.