From 0f234d730f0c5789357ed33e038325b809a25e69 Mon Sep 17 00:00:00 2001 From: IrvingGao <1729854488@qq.com> Date: Fri, 21 Jun 2024 14:55:04 +0800 Subject: [PATCH] [log] print --- takway/clients/client_utils.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/takway/clients/client_utils.py b/takway/clients/client_utils.py index 30c8781..ef444f2 100644 --- a/takway/clients/client_utils.py +++ b/takway/clients/client_utils.py @@ -152,21 +152,9 @@ class BaseWebSocketClient: def receive_per_data(self): try: recv_data = self.websocket.recv() + print(f"{datetime.now()}: receive websocket data.") except websocket._exceptions.WebSocketConnectionClosedException: return None, None - ''' - try: - recv_data = json.loads(recv_data) - #解析头信息,假设头信息前 8 个字节包含两个长度字段 - except json.JSONDecodeError as e: - # print(f"JSONDecodeError: {e}") - # is_end = True - pass - except Exception as e: - # print(f"receive_per_data error: {e}") - assert isinstance(recv_data, bytes), ValueError(f"Received data is not bytes, got {type(recv_data)}.") - return recv_data, type(recv_data) - ''' try: #解析头信息,假设头信息前 8 个字节包含两个长度字段 @@ -178,14 +166,14 @@ class BaseWebSocketClient: audio = recv_data[8 + text_length:8 + text_length + audio_length] text = json.loads(text_bytes.decode('utf-8')) - print("Received text:",text) + # print("Received text:",text) #处理音频数据,例如播放音频 - print("Received audio(length):",len(audio)) + # print("Received audio(length):",len(audio)) return [text, audio], list except TypeError as e: try: recv_data = json.loads(recv_data) - print(f"json: {recv_data}") + # print(f"json: {recv_data}") return recv_data, type(recv_data) except json.JSONDecodeError as e: return None, None