mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
refactor: 优化相关打断处理
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user