Pyttsx3 工作得更早,但现在不行了



2019 年 12 月,我的 pyttsx3 模块工作正常,没有错误。几个月后,我卸载了 Python,但在 2020 年 5 月我再次安装了它。但这一次,奇怪的错误来了... 我的操作系统是win10Pro,Python 3.7(更近似的是一样的(,IDE是Pycharm。代码是:


import pyttsx3

def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()

speak("Hello World!")

当我运行它时:

Traceback (most recent call last):
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libweakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3driverssapi5.py", line 3, in <module>
from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesgen__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libctypes__init__.py", line 121, 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 "E:happy v6stackoverflow.py", line 10, in <module>
speak("Hello World!")
File "E:happy v6stackoverflow.py", line 5, in speak
engine = pyttsx3.init()
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagespyttsx3driverssapi5.py", line 6, in <module>
engine = comtypes.client.CreateObject("SAPI.SpVoice")
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient__init__.py", line 110, in GetBestInterface
mod = GetModule(tlib)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient_generate.py", line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient_generate.py", line 184, in _CreateWrapper
mod = _my_import(fullname)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesclient_generate.py", line 24, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypesgen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 726, in <module>
( ['in'], BSTR, 'AdaptationString' )),
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypes__init__.py", line 329, in __setattr__
self._make_methods(value)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libsite-packagescomtypes__init__.py", line 698, in _make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File "C:UsersRomoni GogoiAppDataLocalProgramsPythonPython37libctypes__init__.py", line 123, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported

我不明白。我做什么?如果你知道如何解决它,请与我分享。

这可能会有所帮助。你应该尝试安装Python的工具。我的意思是开发和其他依赖项。安装 python 开发工具的一种方法是apt-get install python-dev如果这不起作用,您将使用 python 版本做同样的事情。

相关内容

最新更新