import sys
reload(sys)
sys.setdefaultencoding('utf8')
import pyttsx
engine = pyttsx.init()
engine.say('hello world')
engine.runAndWait()
當(dāng)我使用pyttsy 嘗試轉(zhuǎn)換輸出語音是時(shí) 出現(xiàn)了這樣的錯(cuò)誤
C:\Python27\python.exe D:/python/ccc.py
Traceback (most recent call last):
File "D:/python/ccc.py", line 6, in <module>
engine = pyttsx.init()
File "C:\Python27\lib\site-packages\pyttsx\__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\engine.py", line 45, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\driver.py", line 66, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 37, in buildDriver
return SAPI5Driver(proxy)
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 41, in __init__
self._tts = win32com.client.Dispatch('SAPI.SPVoice')
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, '\xce\xde\xd0\xa7\xb5\xc4\xc0\xe0\xd7\xd6\xb7\xfb\xb4\xae', None, None)
請(qǐng)問這是什么原因呢?
pyttsx 應(yīng)該是調(diào)用 win32com.client.
這個(gè)模塊比較有趣, 可以直接獲取 windows 下很多程序的控制權(quán).
比如操作EXCEL:
excel_app = win32com.client.Dispatch('Excel.Application')
excel_app.Visible = True # 使 EXCEL 程序可見
excel_app.Worksheets(1).Cells(1, 1).Value = 'Something' # 設(shè)置單元格(A,1)內(nèi)容
而 pyttsx 作為 win32com.client 的一個(gè)代理, 是調(diào)用了微軟的RRSApp
self._tts = win32com.client.Dispatch('SAPI.SPVoice')
報(bào)錯(cuò)pywintypes.com_error: (-2147221005, '\xce\xde\xd0\xa7\xb5\xc4\xc0\xe0\xd7\xd6\xb7\xfb\xb4\xae', None, None)
意思是"無效的字符串", 這個(gè)錯(cuò)誤說明程序SAPI.SPVoice
不能被識(shí)別。推測(cè)應(yīng)該是題主的 windows 尚未安裝 Speech SDK.
參考Where can I download the SAPI 5.3 SDK?, 應(yīng)該去微軟的官網(wǎng)看看有沒有合適的 Speech SDK 下載安裝.
另外, Use Python for Windows for SAPI5 speech中提到
If necessary, download and install Microsoft [SAPI5SpeechInstaller.msi](https://www.microsoft.com/en-us/download/details.aspx?id=10121). Current Windows systems include speech by default, and the current Windows Software Development Kit includes up-to-date speech components for programmers.
可以嘗試一下下載這個(gè)Speech SDK.
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問,美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。