refactor: 优化相关打断处理

This commit is contained in:
Sakura-RanChen
2026-04-09 10:46:46 +08:00
parent c5f82369e5
commit e08eb48d9a
9 changed files with 204 additions and 164 deletions
@@ -45,7 +45,6 @@ async def sendAudioMessage(conn: "ConnectionHandler", sentenceType, audios, text
# 发送结束消息(如果是最后一个文本)
if sentenceType == SentenceType.LAST:
await send_tts_message(conn, "stop", None)
conn.client_is_speaking = False
if conn.close_after_chat:
await conn.close()
@@ -270,6 +269,8 @@ async def send_tts_message(conn: "ConnectionHandler", state, text=None):
# TTS播放结束
if state == "stop":
# 保存当前的 sentence_id,用于后续判断是否是当前轮次
current_sentence_id = conn.sentence_id
# 播放提示音
tts_notify = conn.config.get("enable_stop_tts_notify", False)
if tts_notify:
@@ -283,8 +284,8 @@ async def send_tts_message(conn: "ConnectionHandler", state, text=None):
# 停止音频发送循环(仅在流控器已初始化时调用)
if hasattr(conn, "audio_rate_controller") and conn.audio_rate_controller:
conn.audio_rate_controller.stop_sending()
# 清除服务端讲话状态
conn.clearSpeakStatus()
# 清除服务端讲话状态,传入 sentence_id 用于判断是否是当前轮次
conn.clearSpeakStatus(current_sentence_id)
# 发送消息到客户端
await conn.websocket.send(json.dumps(message))