[bug] board
This commit is contained in:
1 parent
6a9edd9139
commit
2a298fb5e2
3 files changed
+113
-46
No files matched your search
@@ -3,7 +3,7 @@ import json
|
||||
import time
|
||||
import datetime
|
||||
import requests
|
||||
|
||||
import struct
|
||||
from takway.common_utils import encode_bytes2str, decode_str2bytes
|
||||
|
||||
'''
|
||||
@@ -154,8 +154,10 @@ class BaseWebSocketClient:
|
||||
recv_data = self.websocket.recv()
|
||||
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
|
||||
@@ -163,4 +165,28 @@ class BaseWebSocketClient:
|
||||
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)
|
||||
return recv_data, type(recv_data)
|
||||
'''
|
||||
|
||||
try:
|
||||
#解析头信息,假设头信息前 8 个字节包含两个长度字段
|
||||
header = recv_data[:8]
|
||||
text_length, audio_length = struct.unpack('!II', header)
|
||||
|
||||
#提取文本和二进制音频数据
|
||||
text_bytes = recv_data[8:8 + text_length]
|
||||
audio = recv_data[8 + text_length:8 + text_length + audio_length]
|
||||
text = text_bytes.decode('utf-8')
|
||||
|
||||
print("Received text:",text)
|
||||
#处理音频数据,例如播放音频
|
||||
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}")
|
||||
return recv_data, type(recv_data)
|
||||
except json.JSONDecodeError as e:
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user