mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
add:实时打断对话
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def handleAbortMessage(conn):
|
||||
logger.info("Abort message received")
|
||||
# 设置成打断状态,会自动打断llm、tts任务
|
||||
conn.client_abort = True
|
||||
# 打断屏显任务
|
||||
conn.stop_all_tasks()
|
||||
# 打断客户端说话状态
|
||||
await conn.websocket.send(json.dumps({"type": "tts", "state": "stop", "session_id": conn.session_id}))
|
||||
conn.clearSpeakStatus()
|
||||
logger.info("Abort message received-end")
|
||||
@@ -20,6 +20,7 @@ async def handleAudioMessage(conn, audio):
|
||||
conn.asr_audio.append(audio)
|
||||
# 如果本段有声音,且已经停止了
|
||||
if conn.client_voice_stop:
|
||||
conn.client_abort = False
|
||||
conn.asr_server_receive = False
|
||||
text, file_path = conn.asr.speech_to_text(conn.asr_audio, conn.session_id)
|
||||
logger.info(f"识别文本: {text}")
|
||||
|
||||
Reference in New Issue
Block a user