tried pyttsx3==2.71 and still getting an error
Traceback (most recent call last):
File «C:UsersAdministratorvenvlibsite-packagespyttsx3_init_.py», line 20, in init
eng = _activeEngines[driverName]
File «C:python3libweakref.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 «C:UsersAdministratorvenvlibsite-packageswin32comclientdynamic.py», line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, ‘Invalid class string’, None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «D:/downloads/ferrer/t2s.py», line 2, in
engine = pyttsx3.init()
File «C:UsersAdministratorvenvlibsite-packagespyttsx3_init_.py», line 22, in init
eng = Engine(driverName, debug)
File «C:UsersAdministratorvenvlibsite-packagespyttsx3engine.py», line 30, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File «C:UsersAdministratorvenvlibsite-packagespyttsx3driver.py», line 52, in init
self._driver = self._module.buildDriver(weakref.proxy(self))
File «C:UsersAdministratorvenvlibsite-packagespyttsx3driverssapi5.py», line 23, in buildDriver
return SAPI5Driver(proxy)
File «C:UsersAdministratorvenvlibsite-packagespyttsx3driverssapi5.py», line 28, in init
self.tts = win32com.client.Dispatch(‘SAPI.SPVoice’)
File «C:UsersAdministratorvenvlibsite-packageswin32comclient_init.py», line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File «C:UsersAdministratorvenvlibsite-packageswin32comclientdynamic.py», line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File «C:UsersAdministratorvenvlibsite-packageswin32comclientdynamic.py», line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, ‘Invalid class string’, None, None)
Захотел сделать голосового помощника на питоне, начал с азов.
Установил по очереди pywin32, pypiwin32, pyttsx3.
Написал простейший код
import pyttsx3
engine = pyttsx3.init()
engine.say("I WILL DESTROY HUMANITY")
engine.runAndWait()
Но выдает такую ошибку
Traceback (most recent call last):
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3__init__.py», line 20, in init
eng = _activeEngines[driverName]
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libweakref.py», line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3driverssapi5.py», line 3, in
from comtypes.gen import SpeechLib # comtypes
ImportError: cannot import name ‘SpeechLib’ from ‘comtypes.gen’ (C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesgen__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libctypes__init__.py», line 123, in WINFUNCTYPE
return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (, (, ), 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «C:/Users/Tair/PycharmProjects/untitled/xz che eto.py», line 2, in
engine = pyttsx3.init()
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3__init__.py», line 22, in init
eng = Engine(driverName, debug)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3engine.py», line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3driver.py», line 50, in __init__
self._module = importlib.import_module(name)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libimportlib__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:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagespyttsx3driverssapi5.py», line 6, in
engine = comtypes.client.CreateObject(«SAPI.SpVoice»)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient__init__.py», line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient__init__.py», line 188, in _manage
obj = GetBestInterface(obj)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient__init__.py», line 110, in GetBestInterface
mod = GetModule(tlib)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient_generate.py», line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient_generate.py», line 184, in _CreateWrapper
mod = _my_import(fullname)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesclient_generate.py», line 24, in _my_import
return __import__(fullname, globals(), locals(), [‘DUMMY’])
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypesgen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py», line 33, in
ISpeechDataKey._methods_ = [
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypes__init__.py», line 329, in __setattr__
self._make_methods(value)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libsite-packagescomtypes__init__.py», line 698, in _make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File «C:UsersTairAppDataLocalProgramsPythonPython38-32libctypes__init__.py», line 125, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
I had a program (using module pyttsx3) written in Windows which I used to run on python3.7, and it used to run well.
But,when I try to run it on Ubuntu 20.04, it doesn’t run.
I have both python3.8.2 and python3.7.7 installed on my Ubuntu 20.04 PC, running the program with python3.8.2 interpreter gives the following errors:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 19, in <module>
core("I am ready", "a", "b")
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 17, in core
voice.core(x, id)
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/voice.py", line 15, in core
engine = pyttsx3.init()
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory
On the other hand, running it with python3.7 interpreter gives the following ModuleNotFoundError:
.
.
.
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
…but, when I check the installed modules using the command pip3 list
, pyttsx3 shows up in the list with version: 2.87
Now, I am clueless!…dunno what to do.
UPDATE-1 (pipenv)
I tried running it with pipenv
using the following commands as suggested in the answer by @ivan-borshchov :
pipenv --three
pipenv install pyttsx3
pipenv run python3 MyPythonFile.py
…but this gives the following errors which are somewhat similar to the errors I get when using python3.8.2 interpreter.
Traceback (most recent call last):
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "axon.py", line 6, in <module>
import proice
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 19, in <module>
core("I am ready", "a", "b")
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 17, in core
voice.core(x, id)
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/voice.py", line 15, in core
engine = pyttsx3.init()
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory
UPDATE-2 (pipenv run python3.7 …)
Okay while fiddling with pipenv
, I found that running python3.7 in pipenv is again giving the ModuleNotFoundError, the same as I get when running my program in python3.7 without pipenv (Even though, I have installed pyttsx3 in pipenv as mentioned in UPDATE-1 section).
So, then I am curious whether it is possible to install pyttsx3 in python3.7 in pipenv(rather than in python3, in pipenv).
#python #python-3.x #python-module #pyttsx3
#python #python-3.x #python-модуль #pyttsx3
Вопрос:
Я попытался инициализировать движок для pyttsx3. Всякий раз, когда требуется инициализировать движок, появляется ошибка ниже.
Traceback (most recent call last):
File "C:UsersNatarajanlibsite-packagespyttsx3__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:UsersNatarajanlibweakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersNatarajanlibsite-packagespyttsx3driverssapi5.py", line 3, in <module>
from comtypes.gen import SpeechLib # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:UsersNatarajanlibsite-packagescomtypesgen__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersNatarajanlibctypes__init__.py", line 123, in WINFUNCTYPE
return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.wintypes.LP_c_long'>), 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
engine = pyttsx3.init()
File "C:UsersNatarajanlibsite-packagespyttsx3__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:UsersNatarajanlibsite-packagespyttsx3engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:UsersNatarajanlibsite-packagespyttsx3driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:UsersNatarajanlibimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:UsersNatarajanlibsite-packagespyttsx3driverssapi5.py", line 6, in <module>
engine = comtypes.client.CreateObject("SAPI.SpVoice")
File "C:UsersNatarajanlibsite-packagescomtypesclient__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "C:UsersNatarajanlibsite-packagescomtypesclient__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:UsersNatarajanlibsite-packagescomtypesclient__init__.py", line 110, in GetBestInterface
mod = GetModule(tlib)
File "C:UsersNatarajanlibsite-packagescomtypesclient_generate.py", line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:UsersNatarajanlibsite-packagescomtypesclient_generate.py", line 184, in _CreateWrapper
mod = _my_import(fullname)
File "C:UsersNatarajanlibsite-packagescomtypesclient_generate.py", line 24, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "C:UsersNatarajanlibsite-packagescomtypesgen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 370, in <module>
ISpeechBaseStream._methods_ = [
File "C:UsersNatarajanlibsite-packagescomtypes__init__.py", line 329, in __setattr__
self._make_methods(value)
File "C:UsersNatarajanlibsite-packagescomtypes__init__.py", line 698, in _make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File "C:UsersNatarajanlibctypes__init__.py", line 125, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.
>>>
И вот код, который я пробовал:
import pyttsx3
engine = pyttsx3.init()
Я использовал python версии 3.8.1, и пакет имеет последнюю версию, когда я пишу. Пожалуйста, помогите мне в этом вопросе!
Я даже искал его в Google, но это было бесполезно. Я даже не знаю, как кратко описать проблему в Google. Кажется, есть какая-то проблема со встроенными модулями. Но не знаю, что делать. Любой, кто просматривает сообщение, пожалуйста, помогите мне быстро, потому что мне нужно представить его моему учителю.
Ответ №1:
Попробуйте использовать этот код pip uninstall pyttsx3
pip install pyttsx3==2.71
, он сработал для меня. Последнее обновление для вас не поддерживается. извините, если я не прав.
Ответ №2:
Запустите pip install pyttsx3
, чтобы увидеть его зависимости; например, pywin32, comtypes, pypiwin32. Удалите pyttsx3 с его зависимостями ( pip uninstall pyttsx3
, pip uninstall pywin32
, pip uninstall comtypes
, pip uninstall pypiwin32
) и, наконец, запустите pip install pyttsx3
снова. Аве Мария.
Пасаны кто поможет нубу? У меня вот ошибочка, только тапком не бейте. Traceback (most recent call last):
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3__init__.py”, line 20, in init
eng = _activeEngines
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libweakref.py”, line 137, in __getitem__
o = self.data()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packageswin32comclientdynamic.py”, line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, ‘Операция недоступна’, None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “test.py”, line 2, in <module>
engine = pyttsx3.init()
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3__init__.py”, line 22, in init
eng = Engine(driverName, debug)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3engine.py”, line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3driver.py”, line 52, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3driverssapi5.py”, line 23, in buildDriver
return SAPI5Driver(proxy)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagespyttsx3driverssapi5.py”, line 28, in __init__
self._tts = win32com.client.Dispatch(‘SAPI.SPVoice’)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packageswin32comclient__init__.py”, line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packageswin32comclientdynamic.py”, line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File “C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packageswin32comclientdynamic.py”, line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147024770, ‘Не найден указанный модуль.’, None, None)
Hello,
Imported the following:
pip install SpeechRecognition
pip install pyttsx3
pip install PyAudio
Then running the following code for speech recognition
Python
import speech_recognition as sr import pyttsx3 listener = sr.Recognizer() engine = pyttsx3.init() engine.say('I am bubo') #engine.say('what can I do for you') engine.runAndWait() try: with sr.Microphone() as source: print ("listening...") voice = listener.listen(source) command = listener.recognize_google(voice) command = command.lower() if 'alexa' in command: print(command) except: print('something went wrong')
Then getting the following error:
Python
(venv) C:UsersMDocuments%ProjectsPythonproject_test2>python python.py Traceback (most recent call last): File "C:UsersMAppDataRoamingPythonPython39site-packagespyttsx3__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:Program FilesPython39libweakref.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 "C:UsersMDocuments%ProjectsPythonproject_test2python.py", line 7, in <module> engine = pyttsx3.init() File "C:UsersMAppDataRoamingPythonPython39site-packagespyttsx3__init__.py", line 22, in init eng = Engine(driverName, debug) File "C:UsersMAppDataRoamingPythonPython39site-packagespyttsx3engine.py", line 30, in __init__ self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:UsersMAppDataRoamingPythonPython39site-packagespyttsx3driver.py", line 50, in __init__ self._module = importlib.import_module(name) File "C:Program FilesPython39libimportlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 855, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "C:UsersMAppDataRoamingPythonPython39site-packagespyttsx3driverssapi5.py", line 10, in <module> import pythoncom File "C:UsersMAppDataRoamingPythonPython39site-packagespythoncom.py", line 2, in <module> import pywintypes File "C:UsersMAppDataRoamingPythonPython39site-packageswin32libpywintypes.py", line 105, in <module> __import_pywin32_system_module__("pywintypes", globals()) File "C:UsersMAppDataRoamingPythonPython39site-packageswin32libpywintypes.py", line 87, in __import_pywin32_system_module__ raise ImportError("No system module '%s' (%s)" % (modname, filename)) ImportError: No system module 'pywintypes' (pywintypes39.dll) (venv) C:UsersMDocuments%ProjectsPythonproject_test2>
I googled a bit and there was mention of finding a folder from roaming and moving it to site-packages of my python environment so I moved pywin32_system32 to C:Program FilesPython39site-packages (had to make the site-Packages folder. That didn’t work though.
Any ideas anyone please?