import sys
import importlib
import pyttsx3
import pythoncom
pythoncom.CoInitialize()
importlib.reload(sys)
engine=pyttsx3.init()
engine.say('hello world')
engine.runAndWait()
這段代碼在別人電腦上可以運行,在我電腦上卻報下面這樣的錯誤,重裝系統都不行,求大神指教,這個問題困擾了我好幾天了、、、、
Traceback (most recent call last):
File "D:\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "D:\Python\Python36\lib\weakref.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 "D:\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, '無效的類字串', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
e=pyttsx3.init()
File "D:\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "D:\Python\Python36\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "D:\Python\Python36\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "D:\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
return SAPI5Driver(proxy)
File "D:\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 26, in __init__
self._tts = win32com.client.Dispatch('SAPI.SPVoice')
File "D:\Python\Python36\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "D:\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "D:\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, '無效的類字串', None, None)
uj5u.com熱心網友回復:
試試
import pythoncom
from win32com import client
pythoncom.CoInitialize()
engine=client.Dispatch("SAPI.SpVoice")
engine.Speak('hello world')
uj5u.com熱心網友回復:
是你的python版本 問題 要用32位的 我也試了好久 后來改成32位的python就可以啦。。使用64位Python環境就會出現這種問題,顯示沒有注冊,但是64位的我也不知道怎么注冊。uj5u.com熱心網友回復:
這個已然報錯呀,錯的一毛一樣
uj5u.com熱心網友回復:
看看你的系統有沒有語音識別組件。控制面板里面搜索下關鍵字“語音”uj5u.com熱心網友回復:
看下系統是否能打開控制面板里的語音識別,如果不能說明系統缺少這個組件,去下一個就是了,現在很多系統為了省備份ISO都會去掉這個的。uj5u.com熱心網友回復:
import pythoncomfrom win32com import client
pythoncom.CoInitialize()
engine=client.Dispatch("SAPI.SpVoice")
engine.Speak('hello world')
確實可以
uj5u.com熱心網友回復:
我這個也一樣,總是報錯 在init里的那個drivername那里 怎么辦啊 大佬你解決了嗎uj5u.com熱心網友回復:
對的對的,確實是這個問題,下載了語音識別組件就可以發聲了!!!!!!萬分感謝!!!!!!!轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/78191.html
