我正在尝试使用wincl
内置语音系统的线程。但是我遇到了这个错误:
pywintypes.com_error:( - 2147221008,'CoInitialize尚未被调用。',无,无)
我似乎无法破译。
这是我的代码:
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()
你需要在非主线程中调用pythoncom.CoInitialize
或pythoncom.CoInitializeEx
才能在其中使用COM。