I am creating a DIY virtual assistant for fun and exercise in python. I run into a problem when trying to use engine.say in a thread and then use it again in my main program.
I already tried to use engine.endLoop() and other possible solutions from pyttsx docs (engine.stop(), engine.endLoop() etc) but still i didn't make it work. I have seen in some answers about asyncio. But with pip i can't install it and i am not very certain that it will solve my problem.
The Functions:
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
The "Main" program:
Server_Up = threading.Thread(target = Comm_Connection)
Server_Up.start()
while True:
engine = pyttsx.init()
time.sleep(7)
engine.say("Goodmorning")
engine.runAndWait()
And the error i get:
raise RuntimeError('run loop already started')
RuntimeError: run loop already started