[打断低延迟修复]:完成真实播报打断门控修正,包含短保护窗口、用户音色优先和诊断输出

This commit is contained in:
mkbk
2026-06-19 11:27:34 +08:00
parent f1f4885cc5
commit 7c6797aeb0
8 changed files with 222 additions and 32 deletions
+43
View File
@@ -197,6 +197,49 @@ class BargeInTests(unittest.TestCase):
self.assertFalse(monitor.interrupted)
def test_user_profile_match_can_override_render_echo_candidate(self) -> None:
gate = BargeInSpeakerGate(
enabled=True,
user_similarity_threshold=0.62,
assistant_reject_threshold=0.72,
min_rms=0.001,
)
gate.remember_user_segment(segment_for_speaker("owner"))
assistant = AudioSegment(b"\x01\x20\x02\x20" * 320, 16000, 1, 0, 40, {"speaker_id": "assistant"})
frames = [
AudioFrame(
assistant.pcm[: 640 * 2],
16000,
1,
20 * idx,
idx,
{"duration_ms": 20, "speech": True, "speaker_id": "owner"},
)
for idx in (1, 2)
]
transport = MemoryAudioTransport(frames)
transport.start_input()
monitor = AsyncBargeInMonitor(
transport=transport,
vad_provider=EnergyVadProvider(threshold=1),
realtime_stt=None,
speaker_gate=gate,
assistant_profile=gate.assistant_profile(assistant),
assistant_reference=assistant,
echo_guard_ms=0,
min_speech_ms=40,
listen_interval_ms=1,
)
monitor.vad_provider.load()
monitor.start()
deadline = time.monotonic() + 1
while not monitor.interrupted and time.monotonic() < deadline:
time.sleep(0.005)
monitor.stop()
self.assertTrue(monitor.interrupted)
if __name__ == "__main__":
unittest.main()