ctypes.COMError: (-2147201022, None, (None, None, None, 0, None))
import socket
import subprocess
from comtypes.client import CreateObject
import pythoncom
from comtypes.gen import SpeechLib
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
def send_voice(data,host,port):
pythoncom.CoInitialize()
t1 = time.time()
outfile = "welcome.wav"
stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
send_voice如果在跨线程里调用就会报错,报错代码:
stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
解决方法:在线程里面创建引擎和stream:
def send_voice(data,host,port): pythoncom.CoInitialize() engine = CreateObject("SAPI.SpVoice") stream = CreateObject("SAPI.SpFileStream") t1 = time.time() outfile = "d:/welcome.wav" stream.Open(outfil