Python 2.7 RuntimeError:运行循环已在pyttsx中启动
我正在创建一个DIY虚拟助手,用python进行娱乐和锻炼。我在尝试使用引擎时遇到问题。比如在线程中,然后在主程序中再次使用它 我已经尝试使用engine.endLoop()和pyttsx文档中的其他可能的解决方案(engine.stop()、engine.endLoop()等),但仍然没有成功。我已经在一些关于asyncio的答案中看到了。但是有了pip,我无法安装它,我也不确定它是否能解决我的问题 职能:Python 2.7 RuntimeError:运行循环已在pyttsx中启动,python-2.7,runloop,pyttsx,Python 2.7,Runloop,Pyttsx,我正在创建一个DIY虚拟助手,用python进行娱乐和锻炼。我在尝试使用引擎时遇到问题。比如在线程中,然后在主程序中再次使用它 我已经尝试使用engine.endLoop()和pyttsx文档中的其他可能的解决方案(engine.stop()、engine.endLoop()等),但仍然没有成功。我已经在一些关于asyncio的答案中看到了。但是有了pip,我无法安装它,我也不确定它是否能解决我的问题 职能: def portport(): ser = serial.Seria
def portport():
ser = serial.Serial('COM4',9600)
raw_data = ser.read(9)
msg = str(raw_data[3:8])
print msg
ser.close()
return msg
def Comm_Connection():
print("CommConns started")
while True:
global conn
try:
conn, addr = SERVER.accept()
Live_Conns.append(conn)
Server_Send = "Connection established successfully"
Server_Send = pickle.dumps(Server_Send)
Live_Conns[-1].send(Server_Send)
temp = conn.recv(1024)
Server_Receive = pickle.loads(temp)
Live_Name.append(Server_Receive)
Connections = (Live_Name[-1], "Connected")
engine.say(Connections)
engine.runAndWait()
except socket.error as socketerror:
continue
except socket.timeout:
continue
“主要”计划:
我得到的错误是:
raise RUNTIMERROR('运行循环已启动')
RuntimeError:run loop已启动看起来像是您的
,而True
loop正在尝试启动并运行pyttsx引擎,同时它正在通信连接
循环中运行
注意到PyTSX使用自己的内部引擎支持回调和手动迭代,因此您可以考虑沿着下面的线条重写应用程序:
免责声明:我已经对这个库做了足够多的研究,知道手动迭代方法确实有效,但还不足以理解您的特殊需求,因此,YMMV。它看起来像是您的
,而True
循环正在尝试启动并运行pyttsx引擎,同时它正在通信连接中运行
注意到PyTSX使用自己的内部引擎支持回调和手动迭代,因此您可以考虑沿着下面的线条重写应用程序:
免责声明:我已经对这个库做了足够多的研究,知道手动迭代方法确实有效,但还不足以理解您的特殊需求,所以YMMV。因为这是一个常见的问题,我为我的程序找到了解决方案。使用私有变量判断循环是否已启动,然后在使用引擎时结束循环。\u inLoop
如果为True:
engine=pyttsx.init()
因为这是一个常见的问题,我为我的程序想出了一个解决方案。使用私有变量判断循环是否已启动,然后在使用引擎时结束循环。\u inLoop
如果为True:
engine=pyttsx.init()
Server_Up = threading.Thread(target = Comm_Connection)
Server_Up.start()
while True:
engine = pyttsx.init()
time.sleep(7)
engine.say("Goodmorning")
engine.runAndWait()
engine = pyttsx3.init()
engine.say('The quick brown fox jumped over the lazy dog.', 'fox')
engine.startLoop(False)
# engine.iterate() must be called inside Server_Up.start()
Server_Up = threading.Thread(target = Comm_Connection)
Server_Up.start()
engine.endLoop()
time.sleep(7)
engine.say("Goodmorning")
engine.runAndWait()
if engine._inLoop:
engine.endLoop()