Check for computer messages
This commit is contained in:
parent
375192afe6
commit
08cfa9e523
|
@ -1 +1 @@
|
||||||
[{"role": "user", "type": "message", "content": "This is a microphone. I also have an extra microphone.\n"}]
|
[{"role": "user", "type": "message", "content": "There's no fence, but it's like independent units.\n"}]
|
|
@ -177,7 +177,7 @@ async def websocket_communication(WS_URL):
|
||||||
send_queue.put(result)
|
send_queue.put(result)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
# traceback.print_exc()
|
||||||
print(f"Connecting to `{WS_URL}`...")
|
print(f"Connecting to `{WS_URL}`...")
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,17 @@ async def send_messages(websocket: WebSocket):
|
||||||
print("Sending to the device:", type(message), message)
|
print("Sending to the device:", type(message), message)
|
||||||
await websocket.send_json(message)
|
await websocket.send_json(message)
|
||||||
|
|
||||||
async def user_listener():
|
async def listener():
|
||||||
audio_bytes = bytearray()
|
audio_bytes = bytearray()
|
||||||
while True:
|
while True:
|
||||||
message = await from_user.get()
|
while True:
|
||||||
|
if not from_user.empty():
|
||||||
|
message = await from_user.get()
|
||||||
|
break
|
||||||
|
elif not from_computer.empty():
|
||||||
|
message = from_computer.get()
|
||||||
|
break
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
if type(message) == str:
|
if type(message) == str:
|
||||||
message = json.loads(message)
|
message = json.loads(message)
|
||||||
|
@ -188,9 +195,19 @@ async def user_listener():
|
||||||
with open(conversation_history_path, 'w') as file:
|
with open(conversation_history_path, 'w') as file:
|
||||||
json.dump(interpreter.messages, file)
|
json.dump(interpreter.messages, file)
|
||||||
|
|
||||||
print("New message recieved. Breaking.")
|
print("New user message recieved. Breaking.")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Also check if there's any new computer messages
|
||||||
|
if not from_computer.empty():
|
||||||
|
|
||||||
|
with open(conversation_history_path, 'w') as file:
|
||||||
|
json.dump(interpreter.messages, file)
|
||||||
|
|
||||||
|
print("New computer message recieved. Breaking.")
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
async def stream_or_play_tts(sentence):
|
async def stream_or_play_tts(sentence):
|
||||||
|
|
||||||
if os.getenv('TTS_RUNNER') == "server":
|
if os.getenv('TTS_RUNNER') == "server":
|
||||||
|
@ -208,8 +225,8 @@ from uvicorn import Config, Server
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
# Start listening to the user
|
# Start listening
|
||||||
asyncio.create_task(user_listener())
|
asyncio.create_task(listener())
|
||||||
|
|
||||||
# Start watching the kernel if it's your job to do that
|
# Start watching the kernel if it's your job to do that
|
||||||
if os.getenv('CODE_RUNNER') == "server":
|
if os.getenv('CODE_RUNNER') == "server":
|
||||||
|
|
Loading…
Reference in New Issue