diff --git a/main/xiaozhi-server/core/providers/asr/volcengine.py b/main/xiaozhi-server/core/providers/asr/volcengine.py index 8da6af0ad..209343c9b 100644 --- a/main/xiaozhi-server/core/providers/asr/volcengine.py +++ b/main/xiaozhi-server/core/providers/asr/volcengine.py @@ -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 diff --git a/main/xiaozhi-server/core/providers/tts/volcengine.py b/main/xiaozhi-server/core/providers/tts/volcengine.py index eff8b166a..9a167a652 100644 --- a/main/xiaozhi-server/core/providers/tts/volcengine.py +++ b/main/xiaozhi-server/core/providers/tts/volcengine.py @@ -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"):