nateshmbhat / pyttsx3

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

Incompatibility between pyttsx3 and bleak. #214

Open ValGretchev opened 2 years ago

ValGretchev commented 2 years ago

I am using Python 3.9 on Windows 10 It seems that pyttsx3 and bleak modules can't coexist in the same program. I have boiled it down to 3 statements that immediately cause the error: import bleak import pyttsx3 engine = pyttsx3.init()

Traceback (most recent call last): File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\weakref.py", line 134, in getitem o = self.data[key]() KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "<pyshell#2>", line 1, in engine = pyttsx3.init() File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3__init.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\drivers\sapi5.py", line 1, in import comtypes.client # Importing comtypes.client will make the gen subpackage File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\init.py", line 160, in CoInitializeEx() File "C:\Users\Val\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\init__.py", line 151, in CoInitializeEx _ole32.CoInitializeEx(None, flags) File "_ctypes/callproc.c", line 997, in GetResult OSError: [WinError -2147417850] Cannot change thread mode after it is set

I’ve found a temporary “workaround” for this problem. It’s not elegant but works for me in this case. I separated the Bluetooth code from the voice synthesis code and converted the Bluetooth code into an EXE file. I then call it at the appropriate point in the main code. The EXE file blocks the program in the main code until it finishes reading the Bluetooth instrument. The main code then proceeds as normal.

Is there a solution to this problem or do I have to live with it?

moan0s commented 2 years ago

I have a very similar issue when using pyreiz. I have no idea what the cause could be but maybe this helps: https://github.com/pyreiz/pyreiz/issues/14