You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.datakey
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?
The text was updated successfully, but these errors were encountered:
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.datakey
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?
The text was updated successfully, but these errors were encountered: