From b4ecc6996bd8bcfe5cf89f6e7a1dff6a4da76c9d Mon Sep 17 00:00:00 2001 From: xszyou Date: Tue, 10 Jun 2025 23:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A7=E6=80=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --修复因流式音频结束标记提前而导致的麦克风风不释放问题; --使用更短的文本切割。 --- core/fay_core.py | 19 +++++++++++-------- llm/nlp_cognitive_stream.py | 6 +++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/fay_core.py b/core/fay_core.py index 50f8042..a575be0 100644 --- a/core/fay_core.py +++ b/core/fay_core.py @@ -322,7 +322,9 @@ class FeiFei: if is_end and wsa_server.get_web_instance().is_connected(interact.data.get('user')): wsa_server.get_web_instance().add_cmd({"panelMsg": "", 'Username' : interact.data.get('user'), 'robot': f'{cfg.fay_url}/robot/Normal.jpg'}) - if result is not None or is_first or is_end: + if result is not None or is_first or is_end: + if is_end:#如果结束标记,则延迟1秒处理,免得is end比前面的音频tts要快 + time.sleep(1) MyThread(target=self.__process_output_audio, args=[result, interact, text]).start() return result @@ -375,8 +377,9 @@ class FeiFei: is_first = True if interact.data.get('isend'): is_end = True - util.printInfo(1, interact.data.get('user'), '播放音频...') - self.speaking = True + if file_url is not None: + util.printInfo(1, interact.data.get('user'), '播放音频...') + self.speaking = True #自动播报关闭 global auto_play_lock @@ -394,11 +397,11 @@ class FeiFei: pygame.mixer.music.load(file_url) pygame.mixer.music.play() - # 播放过程中计时,直到音频播放完毕 - length = 0 - while length < audio_length: - length += 0.01 - time.sleep(0.01) + # 播放过程中计时,直到音频播放完毕 + length = 0 + while length < audio_length: + length += 0.01 + time.sleep(0.01) if is_end: self.play_end(interact) diff --git a/llm/nlp_cognitive_stream.py b/llm/nlp_cognitive_stream.py index 3ca4b5c..7e2de15 100644 --- a/llm/nlp_cognitive_stream.py +++ b/llm/nlp_cognitive_stream.py @@ -108,7 +108,7 @@ def init_memory_scheduler(): schedule.every().day.at("00:00").do(save_agent_memory) # 设置每天晚上11点执行反思 - schedule.every().day.at("09:41").do(perform_daily_reflection) + schedule.every().day.at("23:00").do(perform_daily_reflection) # 启动定时任务线程 scheduler_thread = MyThread(target=memory_scheduler_thread) @@ -309,7 +309,7 @@ def question(content, username, observation=None): current_username = username # 记录当前会话用户名 full_response_text = "" accumulated_text = "" - punctuation_marks = ["。", "!", "?", ".", "!", "?", "\n"] + punctuation_marks = [",", ",","。", "!", "?", ".", "!", "?", "\n"] is_first_sentence = True # 创建代理 @@ -385,7 +385,7 @@ def question(content, username, observation=None): {observation} """ # 构建消息列表 - messages = [SystemMessage(content=system_prompt), HumanMessage(content=content + "/no_think")] + messages = [SystemMessage(content=system_prompt), HumanMessage(content=content)] # 1. 获取mcp工具 mcp_tools = get_mcp_tools() # 2. 存在mcp工具,走react agent