feat: rename variable

This commit is contained in:
martsforever
2025-11-02 16:55:32 +08:00
parent 66816ad006
commit 46cd7fb46c
@@ -30,11 +30,11 @@ def add_websocket_voice_recognise_route(app: FastAPI):
"OpenAI-Beta": "realtime=v1" "OpenAI-Beta": "realtime=v1"
} }
bailing_socket = None bailian_socket = None
try: try:
# 连接百炼WebSocket # 连接百炼WebSocket
bailing_socket = await websockets.connect(url, additional_headers=headers) bailian_socket = await websockets.connect(url, additional_headers=headers)
print("已连接到百炼WebSocket") print("已连接到百炼WebSocket")
# 发送会话更新事件 # 发送会话更新事件
@@ -55,7 +55,7 @@ def add_websocket_voice_recognise_route(app: FastAPI):
} }
} }
} }
await bailing_socket.send(json.dumps(session_event)) await bailian_socket.send(json.dumps(session_event))
# 创建双向转发任务 # 创建双向转发任务
async def forward_to_bailing(): async def forward_to_bailing():
@@ -79,7 +79,7 @@ def add_websocket_voice_recognise_route(app: FastAPI):
"type": "input_audio_buffer.append", "type": "input_audio_buffer.append",
"audio": encoded_data "audio": encoded_data
} }
await bailing_socket.send(json.dumps(audio_event)) await bailian_socket.send(json.dumps(audio_event))
# print("已转发音频数据到百炼", f"PCM二进制数据,长度: {len(pcm_bytes)} 字节") # print("已转发音频数据到百炼", f"PCM二进制数据,长度: {len(pcm_bytes)} 字节")
except Exception as e: except Exception as e:
@@ -88,7 +88,7 @@ def add_websocket_voice_recognise_route(app: FastAPI):
async def forward_to_client(): async def forward_to_client():
"""将百炼识别结果转发到客户端""" """将百炼识别结果转发到客户端"""
try: try:
async for message in bailing_socket: async for message in bailian_socket:
data = json.loads(message) data = json.loads(message)
print("收到百炼消息", data.get("type")) print("收到百炼消息", data.get("type"))
@@ -120,8 +120,8 @@ def add_websocket_voice_recognise_route(app: FastAPI):
finally: finally:
print("finally ===>>>>>>>>>>>>>>>>>>>>>>>>>>>") print("finally ===>>>>>>>>>>>>>>>>>>>>>>>>>>>")
# 清理连接 # 清理连接
if bailing_socket and bailing_socket.open: if bailian_socket and bailian_socket.open:
await bailing_socket.close() await bailian_socket.close()
if receive_socket.application_state != WebSocketState.DISCONNECTED: if receive_socket.application_state != WebSocketState.DISCONNECTED:
print("关闭websocket") print("关闭websocket")