代码优化

This commit is contained in:
Kevin Wong
2026-01-06 17:15:06 +08:00
parent fbc5cf49d8
commit a7f98c3893
8 changed files with 285 additions and 115 deletions

View File

@@ -225,6 +225,14 @@ async def _broadcast_audio_optimized(pcm_data: bytes):
# 注意:录制在 broadcast_pcm16_realtime 中统一完成,避免重复
# Day 28: 播放期间全局暂停 VAD防止系统听到自己的声音
# 这对于没有回声消除(AEC)的系统至关重要,否则导航提示语音会触发 VAD
# 导致 VAD 误判为用户说话,从而一直占用识别通道
from server_vad import get_server_vad
vad = get_server_vad()
if vad:
vad.set_tts_playing(True)
# 单次调用交给底层 pacing20ms节拍在 broadcast_pcm16_realtime 内部实现)
await broadcast_pcm16_realtime(full_audio)
@@ -232,6 +240,12 @@ async def _broadcast_audio_optimized(pcm_data: bytes):
except Exception as e:
print(f"[AUDIO] 广播音频失败: {e}")
finally:
# 恢复 VAD 检测
from server_vad import get_server_vad
vad = get_server_vad()
if vad:
vad.set_tts_playing(False)
# 清除播放标志
with _playing_lock:
_is_playing = False