![](/img/trans.png)
[英]Why can't I use “Speech.SpVoice” instead of “SAPI.SpVoice” with python and win32com?
[英]Using win32client SAPI.SpVoice with multi-threading leads to pywintypes.com_error
我正在嘗試將線程與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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.