在 Python 中使用 Sapi 语音时出错
Error When Using Sapi Voice in Python
当我使用代码时:
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)
有人可以帮忙吗?谢谢!
我的 Windows 10 系统没有 "Microsoft Mary" - 只有 David 和 Zira。
您可以检查可用的内容:
>>> 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>>
当我使用代码时:
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)
有人可以帮忙吗?谢谢!
我的 Windows 10 系统没有 "Microsoft Mary" - 只有 David 和 Zira。
您可以检查可用的内容:
>>> 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>>