修复 alillm functions/play_music.py 连续播放音乐问题

This commit is contained in:
lijie 2025-04-23 18:10:31 +08:00
parent 37a1dfa96b
commit 347aefaa9f
3 changed files with 13 additions and 7 deletions

View file

@ -722,7 +722,6 @@ class ConnectionHandler:
for response in llm_responses: for response in llm_responses:
content, tools_call = response content, tools_call = response
if "content" in response: if "content" in response:
content = response["content"] content = response["content"]
tools_call = None tools_call = None
@ -813,8 +812,8 @@ class ConnectionHandler:
self.dialogue.put( self.dialogue.put(
Message(role="assistant", content="".join(response_message)) 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.logger.bind(tag=TAG).info("TTS流结束")
self.llm_finish_task = True self.llm_finish_task = True
self.logger.bind(tag=TAG).debug( self.logger.bind(tag=TAG).debug(

View file

@ -8,6 +8,7 @@ import difflib
import traceback import traceback
from pathlib import Path from pathlib import Path
from core.utils import p3 from core.utils import p3
from core.utils.dialogue import Message, Dialogue
from core.handle.sendAudioHandle import send_stt_message from core.handle.sendAudioHandle import send_stt_message
from plugins_func.register import register_function, ToolType, ActionResponse, Action from plugins_func.register import register_function, ToolType, ActionResponse, Action
import json import json
@ -65,10 +66,16 @@ def play_music(conn, song_name: str):
future.add_done_callback(handle_done) future.add_done_callback(handle_done)
conn.dialogue.put(
Message(role="assistant", content="".join("音乐播放成功"))
)
return ActionResponse( return ActionResponse(
action=Action.NONE, result="指令已接收", response="正在为您播放音乐" action=Action.NONE, result="指令已接收", response="正在为您播放音乐"
) )
except Exception as e: except Exception as e:
conn.dialogue.put(
Message(role="assistant", content="".join("音乐播放失败"))
)
logger.bind(tag=TAG).error(f"处理音乐意图错误: {e}") logger.bind(tag=TAG).error(f"处理音乐意图错误: {e}")
return ActionResponse( return ActionResponse(
action=Action.RESPONSE, result=str(e), response="播放音乐时出错了" 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) opus_packets, _ = conn.tts.audio_to_opus_data(tts_file)
conn.audio_play_queue.put((opus_packets, None, 0)) conn.audio_play_queue.put((opus_packets, None, 0))
os.remove(tts_file) os.remove(tts_file)
# else: else:
# conn.ttsClient.send(json.dumps({ "type": 'text',"text": text })) conn.ttsClient.send(json.dumps({ "type": 'text',"text": text }))
# conn.ttsClient.send(json.dumps( { "type": 'finish' })) conn.ttsClient.send(json.dumps( { "type": 'finish' }))
conn.llm_finish_task = True conn.llm_finish_task = True

View file

@ -4,7 +4,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小智服务器测试页面</title> <title>深塔服务器测试页面</title>
<style> <style>
body { body {
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
@ -436,7 +436,7 @@
<body> <body>
<div class="container"> <div class="container">
<h1>小智服务器测试页面</h1> <h1>深塔服务器测试页面</h1>
<div id="scriptStatus" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);"> <div id="scriptStatus" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">
正在加载Opus库...</div> 正在加载Opus库...</div>