From 347aefaa9f3087839d7c1d3de63c67e3b5662daa Mon Sep 17 00:00:00 2001 From: lijie Date: Wed, 23 Apr 2025 18:10:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20alillm=20functions/play=5F?= =?UTF-8?q?music.py=20=E8=BF=9E=E7=BB=AD=E6=92=AD=E6=94=BE=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 3 +-- .../plugins_func/functions/play_music.py | 13 ++++++++++--- main/xiaozhi-server/test/test_page.html | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 1608613b3..664c1a499 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -722,7 +722,6 @@ class ConnectionHandler: for response in llm_responses: content, tools_call = response - if "content" in response: content = response["content"] tools_call = None @@ -813,8 +812,8 @@ class ConnectionHandler: self.dialogue.put( Message(role="assistant", content="".join(response_message)) ) + self.ttsClient.send(json.dumps( { "type": 'finish' })) - self.ttsClient.send(json.dumps( { "type": 'finish' })) self.logger.bind(tag=TAG).info("TTS流结束") self.llm_finish_task = True self.logger.bind(tag=TAG).debug( diff --git a/main/xiaozhi-server/plugins_func/functions/play_music.py b/main/xiaozhi-server/plugins_func/functions/play_music.py index a35c34c80..e4bf403d8 100644 --- a/main/xiaozhi-server/plugins_func/functions/play_music.py +++ b/main/xiaozhi-server/plugins_func/functions/play_music.py @@ -8,6 +8,7 @@ import difflib import traceback from pathlib import Path from core.utils import p3 +from core.utils.dialogue import Message, Dialogue from core.handle.sendAudioHandle import send_stt_message from plugins_func.register import register_function, ToolType, ActionResponse, Action import json @@ -65,10 +66,16 @@ def play_music(conn, song_name: str): future.add_done_callback(handle_done) + conn.dialogue.put( + Message(role="assistant", content="".join("音乐播放成功")) + ) return ActionResponse( action=Action.NONE, result="指令已接收", response="正在为您播放音乐" ) except Exception as e: + conn.dialogue.put( + Message(role="assistant", content="".join("音乐播放失败")) + ) logger.bind(tag=TAG).error(f"处理音乐意图错误: {e}") return ActionResponse( action=Action.RESPONSE, result=str(e), response="播放音乐时出错了" @@ -224,9 +231,9 @@ async def play_local_music(conn, specific_file=None): opus_packets, _ = conn.tts.audio_to_opus_data(tts_file) conn.audio_play_queue.put((opus_packets, None, 0)) os.remove(tts_file) - # else: - # conn.ttsClient.send(json.dumps({ "type": 'text',"text": text })) - # conn.ttsClient.send(json.dumps( { "type": 'finish' })) + else: + conn.ttsClient.send(json.dumps({ "type": 'text',"text": text })) + conn.ttsClient.send(json.dumps( { "type": 'finish' })) conn.llm_finish_task = True diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index 65182c4d3..4879961d4 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -4,7 +4,7 @@ - 小智服务器测试页面 + 深塔服务器测试页面