mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
refactor: 优化相关打断处理
This commit is contained in:
@@ -219,8 +219,8 @@ async def process_intent_result(
|
||||
|
||||
|
||||
def speak_txt(conn: "ConnectionHandler", text):
|
||||
# 记录文本
|
||||
conn.tts_MessageText = text
|
||||
# 记录文本到 sentence_id 映射
|
||||
conn.tts.store_tts_text(conn.sentence_id, text)
|
||||
|
||||
conn.tts.tts_text_queue.put(
|
||||
TTSMessageDTO(
|
||||
|
||||
@@ -26,10 +26,6 @@ async def handleAudioMessage(conn: "ConnectionHandler", audio):
|
||||
if not hasattr(conn, "vad_resume_task") or conn.vad_resume_task.done():
|
||||
conn.vad_resume_task = asyncio.create_task(resume_vad_detection(conn))
|
||||
return
|
||||
# manual 模式下不打断正在播放的内容
|
||||
if have_voice:
|
||||
if conn.client_is_speaking and conn.client_listen_mode != "manual":
|
||||
await handleAbortMessage(conn)
|
||||
# 设备长时间空闲检测,用于say goodbye
|
||||
await no_voice_close_connect(conn, have_voice)
|
||||
# 接收音频
|
||||
@@ -94,6 +90,10 @@ async def startToChat(conn: "ConnectionHandler", text):
|
||||
|
||||
# 意图未被处理,继续常规聊天流程,使用实际文本内容
|
||||
await send_stt_message(conn, actual_text)
|
||||
|
||||
# 准备开始新会话
|
||||
conn.client_abort = False
|
||||
|
||||
conn.executor.submit(conn.chat, actual_text)
|
||||
|
||||
|
||||
|
||||
@@ -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