[log] print

This commit is contained in:
IrvingGao 2024-06-21 14:55:04 +08:00
parent 0d68b3b490
commit 0f234d730f
1 changed files with 4 additions and 16 deletions

View File

@ -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