将 win32client SAPI.SpVoice 与多线程一起使用会导致 pywintypes.com_error [英] Using win32client SAPI.SpVoice with multi-threading leads to pywintypes.com_error
本文介绍了将 win32client SAPI.SpVoice 与多线程一起使用会导致 pywintypes.com_error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用带有 wincl
内置语音系统的线程.但是我遇到了这个错误:
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 没有被调用.', None, None)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
我似乎无法破译.
这是我的代码:
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.
You need to call pythoncom.CoInitialize
or pythoncom.CoInitializeEx
in a non-main thread to be able to use COM in it.
这篇关于将 win32client SAPI.SpVoice 与多线程一起使用会导致 pywintypes.com_error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文