mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
完善意图识别处理后的流程
This commit is contained in:
parent
150436d14f
commit
5cadd4c95c
4 changed files with 8 additions and 19 deletions
|
|
@ -89,6 +89,7 @@ class ConnectionHandler:
|
||||||
self.auth_code_gen = AuthCodeGenerator.get_instance()
|
self.auth_code_gen = AuthCodeGenerator.get_instance()
|
||||||
self.is_device_verified = False # 添加设备验证状态标志
|
self.is_device_verified = False # 添加设备验证状态标志
|
||||||
self.music_handler = _music
|
self.music_handler = _music
|
||||||
|
self.close_after_chat = False # 是否在聊天结束后关闭连接
|
||||||
|
|
||||||
async def handle_connection(self, ws):
|
async def handle_connection(self, ws):
|
||||||
try:
|
try:
|
||||||
|
|
@ -383,6 +384,6 @@ class ConnectionHandler:
|
||||||
self.chat(text)
|
self.chat(text)
|
||||||
|
|
||||||
# After chat is complete, close the connection
|
# After chat is complete, close the connection
|
||||||
asyncio.run_coroutine_threadsafe(self.close(), self.loop)
|
self.close_after_chat = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.bind(tag=TAG).error(f"Chat and close error: {str(e)}")
|
self.logger.bind(tag=TAG).error(f"Chat and close error: {str(e)}")
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,7 @@ async def check_direct_exit(conn, text):
|
||||||
for cmd in cmd_exit:
|
for cmd in cmd_exit:
|
||||||
if text == cmd:
|
if text == cmd:
|
||||||
logger.bind(tag=TAG).info(f"识别到明确的退出命令: {text}")
|
logger.bind(tag=TAG).info(f"识别到明确的退出命令: {text}")
|
||||||
conn.asr_server_receive = True
|
await conn.close()
|
||||||
conn.asr_audio.clear()
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -80,6 +79,8 @@ async def process_intent_result(conn, intent, original_text):
|
||||||
if "结束聊天" in intent:
|
if "结束聊天" in intent:
|
||||||
logger.bind(tag=TAG).info(f"识别到退出意图: {intent}")
|
logger.bind(tag=TAG).info(f"识别到退出意图: {intent}")
|
||||||
|
|
||||||
|
#如果正在播放音乐,可以关了 TODO
|
||||||
|
|
||||||
# 如果是明确的离别意图,发送告别语并关闭连接
|
# 如果是明确的离别意图,发送告别语并关闭连接
|
||||||
await send_stt_message(conn, original_text)
|
await send_stt_message(conn, original_text)
|
||||||
conn.executor.submit(conn.chat_and_close, original_text)
|
conn.executor.submit(conn.chat_and_close, original_text)
|
||||||
|
|
@ -88,12 +89,7 @@ async def process_intent_result(conn, intent, original_text):
|
||||||
# 处理播放音乐意图
|
# 处理播放音乐意图
|
||||||
if "播放音乐" in intent:
|
if "播放音乐" in intent:
|
||||||
logger.bind(tag=TAG).info(f"识别到音乐播放意图: {intent}")
|
logger.bind(tag=TAG).info(f"识别到音乐播放意图: {intent}")
|
||||||
parts = intent.split("[")
|
await conn.music_handler.handle_music_command(conn, intent)
|
||||||
song_name = "随机音乐"
|
|
||||||
if len(parts) > 1:
|
|
||||||
song_name = parts[1].split("]")[0]
|
|
||||||
|
|
||||||
await conn.music_handler.handle_music_command(conn, "播放音乐 "+song_name)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# 其他意图处理可以在这里扩展
|
# 其他意图处理可以在这里扩展
|
||||||
|
|
|
||||||
|
|
@ -43,16 +43,6 @@ async def handleAudioMessage(conn, audio):
|
||||||
conn.reset_vad_states()
|
conn.reset_vad_states()
|
||||||
|
|
||||||
|
|
||||||
async def handleCMDMessage(conn, text):
|
|
||||||
cmd_exit = conn.cmd_exit
|
|
||||||
for cmd in cmd_exit:
|
|
||||||
if text == cmd:
|
|
||||||
logger.bind(tag=TAG).info("识别到明确的退出命令".format(text))
|
|
||||||
await conn.close()
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def startToChat(conn, text):
|
async def startToChat(conn, text):
|
||||||
# 首先进行意图分析
|
# 首先进行意图分析
|
||||||
intent_handled = await handle_user_intent(conn, text)
|
intent_handled = await handle_user_intent(conn, text)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ async def sendAudioMessage(conn, audios, text, text_index=0):
|
||||||
# 发送结束消息(如果是最后一个文本)
|
# 发送结束消息(如果是最后一个文本)
|
||||||
if conn.llm_finish_task and text_index == conn.tts_last_text_index:
|
if conn.llm_finish_task and text_index == conn.tts_last_text_index:
|
||||||
await send_tts_message(conn, 'stop', None)
|
await send_tts_message(conn, 'stop', None)
|
||||||
|
if conn.close_after_chat:
|
||||||
|
await conn.close()
|
||||||
|
|
||||||
async def send_tts_message(conn, state, text=None):
|
async def send_tts_message(conn, state, text=None):
|
||||||
"""发送 TTS 状态消息"""
|
"""发送 TTS 状态消息"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue