From d59bce5107f00c3124d3c29c0675bda3faba3066 Mon Sep 17 00:00:00 2001 From: Ben Xu Date: Tue, 18 Jun 2024 09:55:32 -0700 Subject: [PATCH] stash local debug statements --- software/source/clients/base_device.py | 8 +++++++ software/source/server/async_interpreter.py | 4 ++-- software/source/server/async_server.py | 25 +-------------------- software/start.py | 2 ++ 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/software/source/clients/base_device.py b/software/source/clients/base_device.py index a53e915..18eef14 100644 --- a/software/source/clients/base_device.py +++ b/software/source/clients/base_device.py @@ -155,6 +155,7 @@ class Device: async def play_audiosegments(self): """Plays them sequentially.""" + print("play audiosegments called!!!") mpv_command = ["mpv", "--no-cache", "--no-terminal", "--", "fd://0"] mpv_process = subprocess.Popen( @@ -332,6 +333,7 @@ class Device: self.fetch_image_from_camera() async def message_sender(self, websocket): + print("message sender running!!!") while True: message = await asyncio.get_event_loop().run_in_executor( None, send_queue.get @@ -354,6 +356,7 @@ class Device: else: print("\nHold the spacebar to start recording. Press CTRL-C to exit.") + print("calling message sender") asyncio.create_task(self.message_sender(websocket)) while True: @@ -430,10 +433,12 @@ class Device: await asyncio.sleep(2) async def start_async(self): + print("start async called!!!!") # Configuration for WebSocket WS_URL = f"ws://{self.server_url}" # Start the WebSocket communication await self.websocket_communication(WS_URL) + print("ws communication called!") # Start watching the kernel if it's your job to do that if os.getenv("CODE_RUNNER") == "client": @@ -441,6 +446,7 @@ class Device: asyncio.create_task(put_kernel_messages_into_queue(send_queue)) asyncio.create_task(self.play_audiosegments()) + print("play audiosegments called!!") # If Raspberry Pi, add the button listener, otherwise use the spacebar if current_platform.startswith("raspberry-pi"): @@ -469,8 +475,10 @@ class Device: on_press=self.on_press, on_release=self.on_release ) listener.start() + print("listener started!!!!!!!!") def start(self): + print("start client called!") if os.getenv("TEACH_MODE") != "True": asyncio.run(self.start_async()) p.terminate() diff --git a/software/source/server/async_interpreter.py b/software/source/server/async_interpreter.py index a2d78bf..1c58b8c 100644 --- a/software/source/server/async_interpreter.py +++ b/software/source/server/async_interpreter.py @@ -102,7 +102,7 @@ class AsyncInterpreter: # print("ADDING TO QUEUE:", chunk) asyncio.create_task(self._add_to_queue(self._output_queue, chunk)) - def generate(self, message, start_interpreter): + def generate(self, message): last_lmc_start_flag = self._last_lmc_start_flag self.interpreter.messages = self.active_chat_messages @@ -179,7 +179,7 @@ class AsyncInterpreter: # self.stt_latency = end_stt - start_stt # print("STT LATENCY", self.stt_latency) - # print(message) + print(message) # Feed generate to RealtimeTTS self.add_to_output_queue_sync( diff --git a/software/source/server/async_server.py b/software/source/server/async_server.py index b88fa57..7c815ab 100644 --- a/software/source/server/async_server.py +++ b/software/source/server/async_server.py @@ -56,13 +56,9 @@ async def main(server_host, server_port, tts_service, asynchronous): print("🪼🪼🪼🪼🪼🪼 Messages loaded: ", interpreter.active_chat_messages) return {"status": "success"} - print("About to set up the websocker endpoint!!!!!!!!!!!!!!!!!!!!!!!!!") - @app.websocket("/") async def websocket_endpoint(websocket: WebSocket): - print("websocket hit") await websocket.accept() - print("websocket accepted") async def send_output(): try: @@ -70,20 +66,17 @@ async def main(server_host, server_port, tts_service, asynchronous): output = await interpreter.output() if isinstance(output, bytes): - print("server sending bytes output") try: await websocket.send_bytes(output) - print("server successfully sent bytes output") except Exception as e: print(f"Error: {e}") traceback.print_exc() return {"error": str(e)} elif isinstance(output, dict): - print("server sending text output") try: await websocket.send_text(json.dumps(output)) - print("server successfully sent text output") + except Exception as e: print(f"Error: {e}") traceback.print_exc() @@ -129,24 +122,8 @@ async def main(server_host, server_port, tts_service, asynchronous): send_task = asyncio.create_task(send_output()) receive_task = asyncio.create_task(receive_input()) - print("server starting to handle ws connection") - """ - done, pending = await asyncio.wait( - [send_task, receive_task], - return_when=asyncio.FIRST_COMPLETED, - ) - - for task in pending: - task.cancel() - - for task in done: - if task.exception() is not None: - raise - """ await asyncio.gather(send_task, receive_task) - print("server finished handling ws connection") - except WebSocketDisconnect: print("WebSocket disconnected") except Exception as e: diff --git a/software/start.py b/software/start.py index 6db7ebb..de206cf 100644 --- a/software/start.py +++ b/software/start.py @@ -176,6 +176,7 @@ def _run( ), ) server_thread.start() + print("server thread started") if expose: tunnel_thread = threading.Thread( @@ -208,6 +209,7 @@ def _run( target=module.main, args=[server_url, tts_service] ) client_thread.start() + print("client thread started") try: if server: