increase interval

This commit is contained in:
xiehao.0527 2025-07-12 12:47:47 +08:00
parent 1b890a619e
commit 058bf11052
2 changed files with 10 additions and 8 deletions

View file

@ -130,8 +130,8 @@ class ASRProvider(ASRProviderBase):
await self._send_audio_chunk(b"".join(pcm_frame)) await self._send_audio_chunk(b"".join(pcm_frame))
conn.asr_audio.clear() conn.asr_audio.clear()
except Exception as e: except Exception as e:
await self.stop_ws_connection()
logger.bind(tag=TAG).error(f"Error sending audio data: {e}", exc_info=True) logger.bind(tag=TAG).error(f"Error sending audio data: {e}", exc_info=True)
await self.stop_ws_connection()
# Finish the session if end-of-utterance is detected. # Finish the session if end-of-utterance is detected.
if self.ws and self.session_started and self.is_eou(conn, self.text) : if self.ws and self.session_started and self.is_eou(conn, self.text) :
@ -340,12 +340,13 @@ class ASRProvider(ASRProviderBase):
logger.bind(tag=TAG).info(f"Connecting to {self.ws_url}") logger.bind(tag=TAG).info(f"Connecting to {self.ws_url}")
headers = {"Authorization": f"Bearer {self.api_key}"} headers = {"Authorization": f"Bearer {self.api_key}"}
# 使用内置的 ping/pong 机制来维持连接和检查健康状况 # 使用内置的 ping/pong 机制来维持连接和检查健康状况
# 每 20 秒发送一次 ping,等待 10 秒超时 # 每 60 秒发送一次 ping,等待 30 秒超时
self.ws = await websockets.connect( self.ws = await websockets.connect(
self.ws_url, self.ws_url,
additional_headers=headers, additional_headers=headers,
ping_interval=20, ping_interval=60, # Increased from 20
ping_timeout=10 ping_timeout=30, # Increased from 10
close_timeout=10 # Added for graceful close
) )
logger.bind(tag=TAG).info("WebSocket connection established.") logger.bind(tag=TAG).info("WebSocket connection established.")
except Exception as e: except Exception as e:

View file

@ -312,12 +312,13 @@ class TTSProvider(TTSProviderBase):
logger.bind(tag=TAG).info(f"Connecting to {self.ws_url}") logger.bind(tag=TAG).info(f"Connecting to {self.ws_url}")
headers = {"Authorization": f"Bearer {self.api_key}"} headers = {"Authorization": f"Bearer {self.api_key}"}
# 使用内置的 ping/pong 机制来维持连接和检查健康状况 # 使用内置的 ping/pong 机制来维持连接和检查健康状况
# 每 20 秒发送一次 ping,等待 10 秒超时 # 每 60 秒发送一次 ping,等待 30 秒超时
self.ws = await websockets.connect( self.ws = await websockets.connect(
self.ws_url, self.ws_url,
additional_headers=headers, additional_headers=headers,
ping_interval=20, ping_interval=60,
ping_timeout=10 ping_timeout=30,
close_timeout=10
) )
logger.bind(tag=TAG).info("WebSocket connection established.") logger.bind(tag=TAG).info("WebSocket connection established.")
except Exception as e: except Exception as e: