如何解决Python pyttsx3在启动时引发错误
Python 3.6
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.runAndWait()
在启动时,出现错误:
Traceback (most recent call last):
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\__init__.py",line 20,in init
eng = _activeEngines[driverName]
File "C:\Users\andre\AppData\Local\Programs\Python\python36\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 "C:/Users/andre/PycharmProjects/Ilona/main.py",line 2,in <module>
engine = pyttsx3.init()
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\__init__.py",line 22,in init
eng = Engine(driverName,debug)
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\engine.py",line 30,in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self),driverName,debug)
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\driver.py",line 52,in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py",in buildDriver
return SAPI5Driver(proxy)
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py",line 47,in __init__
self.setProperty('voice',self.getProperty('voice'))
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py",line 100,in setProperty
token = self._tokenFromId(value)
File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py",line 80,in _tokenFromId
tokens = self._tts.GetVoices()
_ctypes.COMError: (-2147200967,None,(None,None))
已安装Pywin32,pypiwin32和pyttsx3模块。
使用PyCharm。
该怎么办?
解决方法
打开命令提示符/终端,然后键入:
-
pip uninstall pyttsx3
-
pip install pyttsx3==2.71
如果这样不起作用,请用engine=pyttsx3.init()
替换engine=pyttsx3.init('dummy')
-
pip uninstall pyttsx3
-
pip install -u pipenv
-
pipenv install pyttsx3
希望这行得通
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。