Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility between pyttsx3 and bleak. #214

Open
ValGretchev opened this issue Nov 8, 2021 · 2 comments
Open

Incompatibility between pyttsx3 and bleak. #214

ValGretchev opened this issue Nov 8, 2021 · 2 comments
Assignees
Labels

Comments

@ValGretchev
Copy link

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?

@moan0s
Copy link

moan0s commented Feb 4, 2022

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

@willwade willwade self-assigned this Oct 17, 2024
@willwade
Copy link
Collaborator

This is crazy. I’ll look into this. If anyone has some code snippet that would be useful (I reckon it could be similar to #230 )

@willwade willwade added the bug label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants