pyttsx3 icon indicating copy to clipboard operation
pyttsx3 copied to clipboard

engine = pyttsx3.init('sapi5') causeing error

Open NasaHari opened this issue 5 years ago • 6 comments

Traceback (most recent call last): File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3_init_.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\kvvinod\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in getitem o = self.datakey KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\gen_init_.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\kvvinod\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init_.py", line 123, in WINFUNCTYPE return _win_functype_cache[(restype, argtypes, flags)] KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.LP_POINTER(ISpeechRecoGrammar)'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/kvvinod/PycharmProjects/textToSpeech/venv/app.py", line 2, in engine = pyttsx3.init('sapi5') File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3_init_.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3\engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3\driver.py", line 50, in init self.module = importlib.import_module(name) File "C:\Users\kvvinod\AppData\Local\Programs\Python\Python38-32\lib\importlib_init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in call_with_frames_removed File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in engine = comtypes.client.CreateObject("SAPI.SpVoice") File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_init.py", line 250, in CreateObject return manage(obj, clsid, interface=interface) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_init.py", line 188, in manage obj = GetBestInterface(obj) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_init.py", line 110, in GetBestInterface mod = GetModule(tlib) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\client_generate.py", line 24, in my_import return import(fullname, globals(), locals(), ['DUMMY']) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes\gen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 937, in ISpeechRecoContext.methods = [ File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes_init.py", line 329, in setattr self.make_methods(value) File "C:\Users\kvvinod\PycharmProjects\textToSpeech\venv\lib\site-packages\comtypes_init.py", line 698, in make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\Users\kvvinod\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init.py", line 125, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 1 in argtypes passes a union by value, which is unsupported.

NasaHari avatar Feb 03 '20 15:02 NasaHari

I am getting a similar error.

Traceback (most recent call last): File "E:\Software\sarina-env\lib\site-packages\pyttsx3_init_.py", line 20, in init eng = _activeEngines[driverName] File "E:\Software\sarina-env\lib\weakref.py", line 137, in getitem o = self.datakey KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "E:\Software\sarina-env\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (E:\Software\sarina-env\lib\site-packages\comtypes\gen_init_.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "e:/Software/sarina-env/sarina/sarina.py", line 14, in from sarina.speech import query, synthesiser File "e:\Software\sarina-env\sarina\sarina\speech\query.py", line 18, in from sarina.speech import synthesiser File "e:\Software\sarina-env\sarina\sarina\speech\synthesiser.py", line 7, in text_to_speech_engine = pyttsx3.init() File "E:\Software\sarina-env\lib\site-packages\pyttsx3_init_.py", line 22, in init eng = Engine(driverName, debug) File "E:\Software\sarina-env\lib\site-packages\pyttsx3\engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "E:\Software\sarina-env\lib\site-packages\pyttsx3\driver.py", line 50, in init self.module = importlib.import_module(name) File "E:\Software\sarina-env\lib\importlib_init.py", line 127, in import_module return _bootstrap.gcd_import(name[level:], package, level) File "E:\Software\sarina-env\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in engine = comtypes.client.CreateObject("SAPI.SpVoice") File "E:\Software\sarina-env\lib\site-packages\comtypes\client_init.py", line 250, in CreateObject return manage(obj, clsid, interface=interface) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_init.py", line 188, in manage obj = GetBestInterface(obj) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_init.py", line 110, in GetBestInterface mod = GetModule(tlib) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_generate.py", line 172, in _CreateWrapper generate_module(tlib, ofi, pathname) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module gen.generate_code(list(items.values()), filename=pathname) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 241, in generate_code self.generate_all(items) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 189, in generate_all self.generate(item) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 185, in generate mth(item) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 701, in ComInterface self.generate(itf.get_head()) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 185, in generate mth(item) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 722, in ComInterfaceHead self.generate(base.get_head()) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 185, in generate mth(item) File "E:\Software\sarina-env\lib\site-packages\comtypes\tools\codegenerator.py", line 629, in External comtypes.client.GetModule(ext.tlib) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "E:\Software\sarina-env\lib\site-packages\comtypes\client_generate.py", line 24, in _my_import return import(fullname, globals(), locals(), ['DUMMY']) ModuleNotFoundError: No module named 'comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0'

IllyShaieb avatar Feb 09 '20 17:02 IllyShaieb

I also go this error, reverted to version 2.71 and the problem went away.

rkent avatar Feb 13 '20 09:02 rkent

Does this error occur on the latest build ( v2.84 ) ?

nateshmbhat avatar Mar 14 '20 01:03 nateshmbhat

no, in all versions use comtypes

AEydi avatar Aug 08 '20 23:08 AEydi

I am getting same type of error . Please solve it soon.

pawaneshyadav avatar Oct 16 '22 15:10 pawaneshyadav

L'erreur peut provenir du fait que vous avez nommé votre fichier Python pyttsx3.py, ce qui peut causer des conflits avec l'importation de la bibliothèque pyttsx3 dans votre fichier. Pour éviter ce genre de conflits, il est recommandé de ne pas nommer vos fichiers avec le même nom que les bibliothèques Python que vous utilisez. Pour résoudre ce problème, vous pouvez renommer votre fichier Python en utilisant un autre nom, puis exécuter à nouveau votre code. Cela devrait vous permettre d'initialiser la bibliothèque pyttsx3 sans erreurs.

ShaneKaranepilaye avatar Apr 28 '23 15:04 ShaneKaranepilaye