feat: 准备用上 BaiLianVoiceRecognise

This commit is contained in:
martsforever
2025-11-02 18:28:13 +08:00
parent 8c28f934c8
commit dd4422ff8b
3 changed files with 219 additions and 3 deletions
@@ -83,7 +83,10 @@ def add_websocket_voice_recognise_route(app: FastAPI):
# print("已转发音频数据到百炼", f"PCM二进制数据,长度: {len(pcm_bytes)} 字节")
except Exception as e:
print(f"等待前端的消息出错: {e}")
if "CloseCode.NO_STATUS_RCVD" in str(e):
print("前端连接已断开(无状态码)")
else:
print(f"等待前端的消息出错: {e}")
async def waiting_msg_from_bailian():
"""将百炼识别结果转发到客户端"""
@@ -120,8 +123,11 @@ def add_websocket_voice_recognise_route(app: FastAPI):
finally:
print("finally ===>>>>>>>>>>>>>>>>>>>>>>>>>>>")
# 清理连接
if bailian_socket and bailian_socket.open:
await bailian_socket.close()
if bailian_socket:
try:
await bailian_socket.close()
except:
pass # 忽略关闭时的任何错误
if receive_socket.application_state != WebSocketState.DISCONNECTED:
print("关闭websocket")