Skip to content

Commit b4bb365

Browse files
authored
allow pushing frames to VAD when agent speech is uninterruptible (#4418)
1 parent f565a2a commit b4bb365

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

livekit-agents/livekit/agents/voice/agent_activity.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,19 +735,20 @@ def push_audio(self, frame: rtc.AudioFrame) -> None:
735735
if not self._started:
736736
return
737737

738-
if (
738+
should_discard = bool(
739739
self._current_speech
740740
and not self._current_speech.allow_interruptions
741741
and self._session.options.discard_audio_if_uninterruptible
742-
):
743-
# discard the audio if the current speech is not interruptable
744-
return
742+
)
745743

746-
if self._rt_session is not None:
747-
self._rt_session.push_audio(frame)
744+
if not should_discard:
745+
if self._rt_session is not None:
746+
self._rt_session.push_audio(frame)
748747

748+
# Always forward to _audio_recognition for VAD, even when discarding STT/LLM
749+
# VAD needs frames to detect speech end and update user state correctly
749750
if self._audio_recognition is not None:
750-
self._audio_recognition.push_audio(frame)
751+
self._audio_recognition.push_audio(frame, skip_stt=should_discard)
751752

752753
def push_video(self, frame: rtc.VideoFrame) -> None:
753754
if not self._started:

livekit-agents/livekit/agents/voice/audio_recognition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def stop(self) -> None:
180180
self.update_stt(None)
181181
self.update_vad(None)
182182

183-
def push_audio(self, frame: rtc.AudioFrame) -> None:
183+
def push_audio(self, frame: rtc.AudioFrame, *, skip_stt: bool = False) -> None:
184184
self._sample_rate = frame.sample_rate
185-
if self._stt_ch is not None:
185+
if not skip_stt and self._stt_ch is not None:
186186
self._stt_ch.send_nowait(frame)
187187

188188
if self._vad_ch is not None:

0 commit comments

Comments
 (0)