From 01d55be03234c4acf67d0a5fdc1d54a0c6b112ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Tue, 23 Sep 2025 14:11:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E5=A3=B0=E9=9F=B3?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=20all=5Faudio=5Freceived=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- audio_processes.py | 20 ++++++++++++++++---- control_system.py | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/audio_processes.py b/audio_processes.py index a9ffc77..d1820e5 100644 --- a/audio_processes.py +++ b/audio_processes.py @@ -1114,12 +1114,17 @@ class OutputProcess: self.end_signal_received = True self.end_signal_time = time.time() # 记录收到结束信号的时间 - # 延迟设置all_audio_received,确保音频真正开始播放后再设置 - # 暂时设置为False,让播放启动逻辑处理 - self.all_audio_received = False + # 关键修复:如果已经通过ALL_AUDIO_RECEIVED信号设置了True,则不要重置为False + # 这解决了语音识别失败时all_audio_received被重置的问题 + if not self.all_audio_received: + # 只有在all_audio_received为False时才设置为False + # 如果已经是True(如语音识别失败处理),保持True + self.all_audio_received = False + else: + print(f"🔧 保持all_audio_received=True(已通过语音识别失败处理设置)") print(f"📥 收到结束信号,状态变化:") print(f" - end_signal_received: True") - print(f" - all_audio_received: False (延迟设置)") + print(f" - all_audio_received: {self.all_audio_received} ({'保持True' if self.all_audio_received else '延迟设置'})") print(f" - completion_sent: False") print(f" - playback_completed: False") @@ -1209,6 +1214,13 @@ class OutputProcess: self.tts_generation_complete = True continue + if isinstance(audio_data, str) and audio_data.startswith("ALL_AUDIO_RECEIVED:"): + # 语音识别失败时设置的all_audio_received信号 + print(f"📥 输出进程收到ALL_AUDIO_RECEIVED信号") + self.all_audio_received = True + print(f"🔧 设置all_audio_received=True(语音识别失败处理)") + continue + # 音频数据处理 if isinstance(audio_data, bytes): # 更新最后收到音频数据的时间 diff --git a/control_system.py b/control_system.py index 8069d7c..1ada6d5 100644 --- a/control_system.py +++ b/control_system.py @@ -643,6 +643,11 @@ class ControlSystem: # 发送TTS完成信号 tts_complete_command = "TTS_COMPLETE:" self.output_audio_queue.put(tts_complete_command) + # 关键修复:处理失败时也要发送all_audio_received=True信号 + # 这解决了语音识别失败但TTS完成信号已发送的死锁问题 + all_audio_received_command = "ALL_AUDIO_RECEIVED:" + self.output_audio_queue.put(all_audio_received_command) + print(f"🔧 处理失败,发送all_audio_received=True信号以避免死锁") # 发送结束信号 self.output_audio_queue.put(None) except Exception as e: