mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
移除没用的connection操作
This commit is contained in:
parent
30f64fb8af
commit
b443c547dd
2 changed files with 3 additions and 8 deletions
|
|
@ -78,7 +78,7 @@ class ASRProvider(ASRProviderBase):
|
||||||
conn: The connection object, which includes session details.
|
conn: The connection object, which includes session details.
|
||||||
"""
|
"""
|
||||||
await super().open_audio_channels(conn)
|
await super().open_audio_channels(conn)
|
||||||
self.current_session_id = conn.session_id
|
await self._ensure_connection()
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
|
|
||||||
async def receive_audio(self, conn, audio: bytes, audio_have_voice: bool):
|
async def receive_audio(self, conn, audio: bytes, audio_have_voice: bool):
|
||||||
|
|
@ -197,7 +197,6 @@ class ASRProvider(ASRProviderBase):
|
||||||
elif message_type == "error":
|
elif message_type == "error":
|
||||||
error_msg = event.get("error", {})
|
error_msg = event.get("error", {})
|
||||||
logger.bind(tag=TAG).error(f"ASR service error: {error_msg}")
|
logger.bind(tag=TAG).error(f"ASR service error: {error_msg}")
|
||||||
await self.stop_ws_connection()
|
|
||||||
break
|
break
|
||||||
|
|
||||||
except websockets.ConnectionClosed:
|
except websockets.ConnectionClosed:
|
||||||
|
|
@ -296,7 +295,6 @@ class ASRProvider(ASRProviderBase):
|
||||||
logger.bind(tag=TAG).info(f"Stopping session {self.current_session_id}")
|
logger.bind(tag=TAG).info(f"Stopping session {self.current_session_id}")
|
||||||
try:
|
try:
|
||||||
self.audio_buffer.clear()
|
self.audio_buffer.clear()
|
||||||
await self._ensure_connection()
|
|
||||||
done_payload = {"type": "input_audio_buffer.commit"}
|
done_payload = {"type": "input_audio_buffer.commit"}
|
||||||
await self.ws.send(json.dumps(done_payload))
|
await self.ws.send(json.dumps(done_payload))
|
||||||
self.session_started = False
|
self.session_started = False
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,6 @@ class TTSProvider(TTSProviderBase):
|
||||||
break # End of stream for this request
|
break # End of stream for this request
|
||||||
elif event_type == "error":
|
elif event_type == "error":
|
||||||
logger.bind(tag=TAG).error(f"Received error from server: {data}")
|
logger.bind(tag=TAG).error(f"Received error from server: {data}")
|
||||||
await self.stop_ws_connection()
|
|
||||||
break
|
break
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
await self.stop_ws_connection()
|
await self.stop_ws_connection()
|
||||||
|
|
@ -264,8 +263,7 @@ class TTSProvider(TTSProviderBase):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self._monitor_task = None
|
self._monitor_task = None
|
||||||
if self.ws:
|
await self.stop_ws_connection()
|
||||||
await self.stop_ws_connection()
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def finish_session(self, session_id):
|
async def finish_session(self, session_id):
|
||||||
|
|
@ -276,7 +274,6 @@ class TTSProvider(TTSProviderBase):
|
||||||
session_id (str): The unique session ID.
|
session_id (str): The unique session ID.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
await self._ensure_connection()
|
|
||||||
done_payload = {
|
done_payload = {
|
||||||
"type": "input_text.done"
|
"type": "input_text.done"
|
||||||
}
|
}
|
||||||
|
|
@ -284,8 +281,8 @@ class TTSProvider(TTSProviderBase):
|
||||||
logger.bind(tag=TAG).debug(f"会话结束请求已发送,Send Event: {done_payload}")
|
logger.bind(tag=TAG).debug(f"会话结束请求已发送,Send Event: {done_payload}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await self.stop_ws_connection()
|
|
||||||
logger.bind(tag=TAG).error(f"关闭会话失败: {str(e)}")
|
logger.bind(tag=TAG).error(f"关闭会话失败: {str(e)}")
|
||||||
|
await self.stop_ws_connection()
|
||||||
|
|
||||||
# 等待监听任务完成
|
# 等待监听任务完成
|
||||||
if hasattr(self, "_monitor_task"):
|
if hasattr(self, "_monitor_task"):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue