移除没用的connection操作

This commit is contained in:
xiehao.0527 2025-07-12 16:52:22 +08:00
parent 30f64fb8af
commit b443c547dd
2 changed files with 3 additions and 8 deletions

View file

@ -78,7 +78,7 @@ class ASRProvider(ASRProviderBase):
conn: The connection object, which includes session details.
"""
await super().open_audio_channels(conn)
self.current_session_id = conn.session_id
await self._ensure_connection()
self.conn = conn
async def receive_audio(self, conn, audio: bytes, audio_have_voice: bool):
@ -197,7 +197,6 @@ class ASRProvider(ASRProviderBase):
elif message_type == "error":
error_msg = event.get("error", {})
logger.bind(tag=TAG).error(f"ASR service error: {error_msg}")
await self.stop_ws_connection()
break
except websockets.ConnectionClosed:
@ -296,7 +295,6 @@ class ASRProvider(ASRProviderBase):
logger.bind(tag=TAG).info(f"Stopping session {self.current_session_id}")
try:
self.audio_buffer.clear()
await self._ensure_connection()
done_payload = {"type": "input_audio_buffer.commit"}
await self.ws.send(json.dumps(done_payload))
self.session_started = False

View file

@ -143,7 +143,6 @@ class TTSProvider(TTSProviderBase):
break # End of stream for this request
elif event_type == "error":
logger.bind(tag=TAG).error(f"Received error from server: {data}")
await self.stop_ws_connection()
break
except websockets.exceptions.ConnectionClosed as e:
await self.stop_ws_connection()
@ -264,8 +263,7 @@ class TTSProvider(TTSProviderBase):
except Exception:
pass
self._monitor_task = None
if self.ws:
await self.stop_ws_connection()
await self.stop_ws_connection()
raise
async def finish_session(self, session_id):
@ -276,7 +274,6 @@ class TTSProvider(TTSProviderBase):
session_id (str): The unique session ID.
"""
try:
await self._ensure_connection()
done_payload = {
"type": "input_text.done"
}
@ -284,8 +281,8 @@ class TTSProvider(TTSProviderBase):
logger.bind(tag=TAG).debug(f"会话结束请求已发送,Send Event: {done_payload}")
except Exception as e:
await self.stop_ws_connection()
logger.bind(tag=TAG).error(f"关闭会话失败: {str(e)}")
await self.stop_ws_connection()
# 等待监听任务完成
if hasattr(self, "_monitor_task"):