diff --git a/core/duplex_pipeline.py b/core/duplex_pipeline.py index fd5c071..9d4a938 100644 --- a/core/duplex_pipeline.py +++ b/core/duplex_pipeline.py @@ -213,26 +213,26 @@ class DuplexPipeline: # 1. Process through VAD vad_result = self.vad_processor.process(pcm_bytes, settings.chunk_size_ms) - vad_status = "Silence" - if vad_result: - event_type, probability = vad_result - vad_status = "Speech" if event_type == "speaking" else "Silence" + vad_status = "Silence" + if vad_result: + event_type, probability = vad_result + vad_status = "Speech" if event_type == "speaking" else "Silence" + + # Emit VAD event + await self.event_bus.publish(event_type, { + "trackId": self.session_id, + "probability": probability + }) + else: + # No state change - keep previous status + vad_status = self._last_vad_status + + # Update state based on VAD + if vad_status == "Speech" and self._last_vad_status != "Speech": + await self._on_speech_start() + + self._last_vad_status = vad_status - # Emit VAD event - await self.event_bus.publish(event_type, { - "trackId": self.session_id, - "probability": probability - }) - else: - # No state change - keep previous status - vad_status = self._last_vad_status - - # Update state based on VAD - if vad_status == "Speech" and self._last_vad_status != "Speech": - await self._on_speech_start() - - self._last_vad_status = vad_status - # 2. Check for barge-in (user speaking while bot speaking) # Filter false interruptions by requiring minimum speech duration if self._is_bot_speaking: