当我使用代码时:
speak = win32com.client.Dispatch('Sapi.SpVoice')
speak.Volume = 100
speak.Rate = 6
speak.Voice = speak.GetVoices('Name=Microsoft Mary').Item(0)
它给了我错误:
speak.Voice = speak.GetVoices('Name=Microsoft Mary').Item(0)
File "C:\Python25\lib\site-packages\win32com\gen_py\C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x4.py", line 1872, in Item
ret = self._oleobj_.InvokeTypes(0, LCID, 1, (9, 0), ((3, 1),),Index
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147200967), None)
有人可以帮忙吗?谢谢!
答案 0 :(得分:2)
我的Windows 10系统没有" Microsoft Mary" - 只有大卫和齐拉。
您可以查看以下内容:
>>> speak.GetVoices().Item(0).GetDescription()
u'Microsoft David Desktop - English (United States)'
>>> speak.GetVoices().Item(1).GetDescription()
u'Microsoft Zira Desktop - English (United States)'
>>> speak.GetVoices().Item(2).GetDescription()
如果我使用其中一个有效:
>>> speak.GetVoices("Name=Microsoft Zira")
<COMObject <unknown>>