修复无声音导致的 all_audio_received问题

This commit is contained in:
朱潮 2025-09-23 14:11:22 +08:00
parent 26a42452c8
commit 01d55be032
2 changed files with 21 additions and 4 deletions

View File

@ -1114,12 +1114,17 @@ class OutputProcess:
self.end_signal_received = True self.end_signal_received = True
self.end_signal_time = time.time() # 记录收到结束信号的时间 self.end_signal_time = time.time() # 记录收到结束信号的时间
# 延迟设置all_audio_received确保音频真正开始播放后再设置 # 关键修复如果已经通过ALL_AUDIO_RECEIVED信号设置了True则不要重置为False
# 暂时设置为False让播放启动逻辑处理 # 这解决了语音识别失败时all_audio_received被重置的问题
self.all_audio_received = False 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"📥 收到结束信号,状态变化:")
print(f" - end_signal_received: True") 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" - completion_sent: False")
print(f" - playback_completed: False") print(f" - playback_completed: False")
@ -1209,6 +1214,13 @@ class OutputProcess:
self.tts_generation_complete = True self.tts_generation_complete = True
continue 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): if isinstance(audio_data, bytes):
# 更新最后收到音频数据的时间 # 更新最后收到音频数据的时间

View File

@ -643,6 +643,11 @@ class ControlSystem:
# 发送TTS完成信号 # 发送TTS完成信号
tts_complete_command = "TTS_COMPLETE:" tts_complete_command = "TTS_COMPLETE:"
self.output_audio_queue.put(tts_complete_command) 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) self.output_audio_queue.put(None)
except Exception as e: except Exception as e: