我想在我的代码中使用pyttsx3,但是我总是有这样的错误:
Traceback (most recent call last):
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\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 "test3.py", line 3, in <module>
engine = pyttsx3.init()
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 30, in buildDriver
return SAPI5Driver(proxy)
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 35, in __init__
self._tts = comtypes.client.CreateObject('SAPI.SPVoice')
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: module 'comtypes.gen.SpeechLib' has no attribute 'ISpeechVoice'我的密码是:
import pyttsx3
engine = pyttsx3.init()
engine.say("This is a test")
engine.runAndWait()你能帮帮我吗?(使用Python3.8.3和Studio代码)
发布于 2020-06-25 13:42:01
我决定用另一个版本重新安装pyttsx3,它成功了(命令:pip uninstall pyttsx3和pip install pyttsx3==2.7)
发布于 2021-05-24 14:41:00
这个问题是由于comtypes的旧版本(pyttsx3中所需的默认模块)而产生的,因此不需要安装旧版本的pyttsx3
只需在cmd中键入以下内容:
pip install --upgrade comtypes现在你可以走了
https://stackoverflow.com/questions/62576302
复制相似问题