使用带有多线程的win32client SAPI.SpVoice会导致pywintypes.com_error

问题描述 投票:0回答:1

我正在尝试使用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()
python multithreading win32com sapi
1个回答
1
投票

你需要在非主线程中调用pythoncom.CoInitializepythoncom.CoInitializeEx才能在其中使用COM。

© www.soinside.com 2019 - 2024. All rights reserved.