Using win32client SAPI.SpVoice with multi-threading leads to pywintypes.com_error

青春壹個敷衍的年華 提交于 2019-12-13 04:11:23

问题


I am trying to use a thread with wincl's built-in voice system. However I am running into this error:

pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

which I can't seem to decipher.

Here is my code:

import win32com.client as wincl
import time, threading


def ten_second_timer():
    t =threading.Timer(10, ten_second_timer)
    speak = wincl.Dispatch("SAPI.SpVoice")
    speak.Speak("10 seconds have passed")
    t.start()


t =threading.Thread(target = ten_second_timer)
t.start()

回答1:


You need to call pythoncom.CoInitialize or pythoncom.CoInitializeEx in a non-main thread to be able to use COM in it.



来源:https://stackoverflow.com/questions/55737030/using-win32client-sapi-spvoice-with-multi-threading-leads-to-pywintypes-com-erro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!