In livekit, when we disable interruptions on a tur...
# ask-ai
p
In livekit, when we disable interruptions on a turn, so when the AI agent is speaking and humans are also speaking, we miss some part of the conversation by the human....Is there some buffer value for the human speech...Can we increase it to catch all the words human said while AI was speaking...This would prevent us from missing any thing they said while the non interrupted AI agent speech was going on..
t
Thanks for reaching out, Basit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether LiveKit can capture human speech that overlaps with an AI agent's non-interruptible reply, and if there's a buffer you can increase so you don't lose any words. Good question — you can prevent lost audio and increase local buffering. What to change • Keep user audio instead of discarding it while the agent is uninterruptible: ◦ Set
discard_audio_if_uninterruptible=False
on the
AgentSession
. ◦ Example:
Copy code
session = AgentSession(
      allow_interruptions=False,
      discard_audio_if_uninterruptible=False,
    )
• Increase the local audio queue to hold more incoming audio frames: ◦ Use
queue_size_ms
on
AudioSource
(try 1000–2000 ms to start). ◦ Example:
Copy code
audio_source = rtc.AudioSource(
      sample_rate=sample_rate,
      num_channels=channels,
      queue_size_ms=2000
    )
Why this helps •
discard_audio_if_uninterruptible=False
ensures incoming user audio continues to be buffered while the agent speaks. •
queue_size_ms
increases how long captured audio is held locally, reducing the chance of dropped frames during overlap so you can transcribe/process it after the agent finishes. If you want, tell me: • which SDK/language you’re using, and • what queue size you’re currently running and I’ll suggest specific values and next steps for testing. Sources: Turn detection and interruptions | LiveKit Docs | Resolving "InvalidState - failed to capture frame" errors in AudioSource
p
where is rtc.AudioSource( sample_rate=sample_rate, num_channels=channels, queue_size_ms=2000 ) in code
t
You're asking where to put the
rtc.AudioSource(...)
instantiation in code. It’s created wherever you build and publish audio for a server-side participant (agent or backend publisher). Common places: • In an Agent's RTC session entrypoint (e.g., inside your
@server.rtc_session()
or equivalent
rtc_session
handler). • In a backend media-ingest module that generates or forwards audio (TTS, file playback, or synthesized audio) before creating a LocalAudioTrack and publishing. Minimal example flow (Python-style): 1. Create the audio source:
Copy code
source = rtc.AudioSource(
  sample_rate=sample_rate,
  num_channels=channels,
  queue_size_ms=2000
)
1. Create a local track from that source:
Copy code
track = rtc.LocalAudioTrack.create_audio_track("audio-track", source)
1. Publish the track from the local participant:
Copy code
await room.local_participant.publish_track(track)
If you tell me which SDK/language you're using (Python, Node, or another) and where in your project you handle the agent/RTPC session, I’ll give a concrete code snippet adapted to your setup. Sources: Camera & microphone | LiveKit docs | Resolving "InvalidState - failed to capture frame" errors in AudioSource | Text-to-speech (TTS) models | LiveKit Docs
p
we have set the queue_size_ms=3000 in audio_source.py in the init but it still doesnt seem to capture the audip when the uninterrupted message is being played.
t
Thanks — I hear your frustration that increasing
queue_size_ms
to 3000 didn’t stop the missing audio. To help diagnose this quickly, a few clarifying questions and targeted checks will pinpoint the cause. Quick questions • Which SDK/language are you using (Python, Node, other)? • Where did you set
queue_size_ms=3000
— in a custom
AudioSource
used to publish agent TTS, or in code that captures user mic audio? Paste the small snippet if possible. • Do you have
discard_audio_if_uninterruptible=False
set on the
AgentSession
(or equivalent) where you set
allow_interruptions=False
? • Is the user audio being published by client-side mic tracks or by a server-side audio source? (i.e., who is the publisher of human audio) • Any logs/errors when audio is missed (e.g., “failed to capture frame” or queue warnings)? Immediate checks to run • Confirm
discard_audio_if_uninterruptible=False
is applied in the same session instance that’s handling the agent speech. • Verify the audio source whose
queue_size_ms
you changed is the one receiving the human audio (increase only affects that source). • Check for dropped-frame or buffer-full logs around the agent’s playback time. • Temporarily set
queue_size_ms
very high (e.g., 5000) to see if behavior changes; if not, buffering may not be the blocking factor. If you share the SDK and the small code bits where you: • construct
AgentSession
(showing
allow_interruptions
and
discard_audio_if_uninterruptible
), and • create the
AudioSource
(the file you edited), I’ll review them and suggest precise changes and tests.
p
we are using python…Coudl EoU be causing the discarding of this text…do we need to change settings in VAD…
t
Thanks — I hear you: Python, queue_size_ms=3000 didn’t help, and you’re asking whether End-of-Utterance (EoU) or VAD might be discarding the user audio. Let’s narrow this down and find the cause. Quick checklist and questions • Confirm
discard_audio_if_uninterruptible=False
is set on the same AgentSession instance used for the agent reply. Do you have that in your session init? Paste the snippet if possible. • Is the human audio published from client-side microphone tracks (browser/mobile) or from a server-side AudioSource? Which publisher is expected to be buffered? • Where did you set
queue_size_ms=3000
— in the server-side AudioSource that publishes agent audio, or in the one that captures/relays user audio? • Do you run any VAD/EoU logic before publishing user audio (client-side or server-side)? If so, what VAD library/settings are you using and what are the thresholds (energy, timeout)? • Any logs around the missing audio (VAD silence detections, “failed to capture frame”, queue-full warnings)? Possible causes and targeted actions • Missing config: If
discard_audio_if_uninterruptible
is not set to False on the AgentSession that’s active during the agent reply, LiveKit will discard user audio. Verify that first. • Wrong AudioSource: Increasing
queue_size_ms
only affects the AudioSource you changed. Ensure the user mic’s AudioSource (or the server-side receiver that buffers user audio) has the increased queue, not only the agent TTS source. • VAD/EoU cutting audio: VAD/EoU can cause early trimming if it marks speech as ended while agent is speaking. If you have VAD/EoU enabled: ◦ Temporarily disable VAD/EoU and test whether the audio is preserved. If disabling fixes it, adjust VAD timeouts or silence thresholds. ◦ Increase EoU/silence timeouts so brief overlaps aren’t treated as end-of-utterance. • Timing/buffering limits: Try a bigger
queue_size_ms
(5000) temporarily to rule out buffer length; also confirm no other layer (client SDK, OS audio, or network) is dropping frames. • Logging: Add detailed logging for VAD state transitions and queue occupancy during the agent reply to see where audio is lost. If you share these small code snippets I’ll review them: 1. Your
AgentSession
constructor (showing
allow_interruptions
and
discard_audio_if_uninterruptible
). 2. The code that creates and publishes the user mic AudioSource (or client-side publishing code). 3. Any VAD/EoU configuration you run before publishing. Send those and I’ll point out the exact setting to change and a small test to confirm it’s fixed.
p
We are using VAD silero before publishing….
t
Thanks — since you’re using Silero VAD, the most likely cause is VAD deciding the user’s overlap is silence/EoU or the pipeline dropping frames. Quick checklist and next actions to diagnose and fix: 1) Confirm session setting • Ensure your AgentSession has:
Copy code
discard_audio_if_uninterruptible=False
allow_interruptions=False
If
discard_audio_if_uninterruptible
is True (default) user audio will be dropped while agent speaks. 2) VAD behavior (Silero) • Silero VAD does not buffer audio — it only emits start/end events. If VAD marks an EoU while agent plays, that voice segment can be trimmed. • Tune these VAD params to avoid early EoU:
Copy code
min_speech_duration=0.1
min_silence_duration=0.5
prefix_padding_duration=0.1
Increase
min_silence_duration
if short overlaps are being cut. 3) Ensure audio frames still reach VAD/STT during agent playback • Confirm your code keeps pushing frames from
rtc.AudioStream(track)
into VAD and STT while the agent is speaking (don’t skip/pause the loop). Example flow:
Copy code
audio_stream = rtc.AudioStream(track)
async for frame in audio_stream:
    await vad_stream.push_frame(frame)
    await stt_stream.push_frame(frame)
4) Verify which AudioSource you changed •
queue_size_ms
affects the AudioSource buffer where you set it. Make sure you increased it on the source that receives/publishes the user mic (or the server receiver used for STT), not only on the TTS/source used to play the agent voice. 5) Logging test to pinpoint loss • Add logs for: ◦ VAD events (START_OF_SPEECH, END_OF_SPEECH) with timestamps ◦ When frames are pushed to STT ◦
discard_audio_if_uninterruptible
value at session start • Reproduce the overlap and compare timestamps to see where audio stops. 6) Quick experiments • Temporarily disable VAD (push raw frames straight to STT) — if missing audio disappears, VAD timing is the cause. • Temporarily set
queue_size_ms=5000
on the relevant AudioSource to rule out buffer length. • If disabling VAD fixes it, gradually increase
min_silence_duration
or add a short prefix padding before treating end-of-utterance as final. If you share these snippets I’ll review them and give exact edits: • Your
AgentSession
constructor • The code that subscribes to the user audio track and pushes to VAD/STT • Your Silero VAD load/configuration I’ll point out the single most likely change to stop the trimming. Sources: Agent speech and audio | LiveKit docs | Resolving "InvalidState - failed to capture frame" errors in AudioSource | Turns overview | LiveKit docs | Silero VAD plugin | LiveKit docs | Speech-to-text (STT) models | LiveKit Docs
p
EoU is getting our transcription but in final STT response that transcription is not there…
t
Thanks — I understand: Silero VAD detects the user speech (you see the EoU/transcript) but that content is missing from the final STT result. Let’s pinpoint where it’s being dropped. Quick checks (please confirm each or paste snippets) 1. AgentSession • Is
discard_audio_if_uninterruptible=False
set on the exact AgentSession instance used during the interaction? 1. STT pipeline: interim vs final • Are you collecting/storing final STT results or only using interim events? Show the code where you handle STT events (callbacks/async loop) and where you assemble the final transcript. 1. Frame flow to STT after EoU • After VAD emits EoU, are you still pushing the remaining frames for that utterance into the STT stream before closing/committing the STT chunk? Paste the code that calls
stt_stream.push_frame(...)
and any flush/close/commit logic. 1. Timing/flush issues • Do you call a final
stt_stream.flush()
/
stt_stream.commit()
(or equivalent) after EoU? If not, final results may never be finalized. • If you do flush/commit, is it possible it runs before all buffered frames are pushed? Immediate suggestions to try • Ensure you push all buffered frames into STT and then explicitly finalize/commit the STT chunk before relying on the final result. • Add logging: timestamp each frame pushed, VAD EoU event, and when you call flush/commit and when final STT arrives. Compare to find the gap. • Temporarily bypass VAD for a test: stream raw frames to STT and see if final contains the segment. If yes, the issue is in how you handle frames around EoU. If you share these three small snippets I’ll point to the exact line to change: • AgentSession init (showing
discard_audio_if_uninterruptible
) • The loop/handler that pushes frames to VAD and STT • The code that finalizes/collects final STT results (flush/commit/assembly) I’ll then give the single fix to ensure the EoU transcription appears in the final STT.
p
We have not made any changes to the standard EoU flow of livekit
t
Thanks — I understand you’re using the default EoU flow and seeing EoU-triggered/interim transcription but the text is missing from the final STT result. Here are the most likely causes and the exact checks/fixes to make. Checklist — confirm each 1. AgentSession flag • Ensure the active AgentSession has:
Copy code
discard_audio_if_uninterruptible=False
allow_interruptions=False
If
discard_audio_if_uninterruptible
is True, frames may be dropped before finalization. 1. Make sure all frames for that utterance are pushed before finalizing • After Silero emits EoU, you must push any remaining buffered frames into the STT stream, then finalize/commit/flush the STT chunk. If you finalize before the last frames arrive, the final result will miss those words. 1. Finalize/flush ordering • Confirm you call the STT finalization only after pushing frames. Typical order: a. push remaining frames -> 2. call
stt_stream.flush()
/
commit()
-> 3. await final result 1. Don’t let VAD prematurely drop frames • VAD detects EoU but does not buffer. If your code clears buffers or stops pushing frames when EoU is seen, that will remove audio before STT finalizes. Keep pushing until you flush/commit. Quick debugging steps (do these now) • Add timestamped logs for: ◦ When each frame is pushed to STT ◦ When VAD emits EoU ◦ When you call STT flush/commit ◦ When final STT arrives • Reproduce overlap and compare logs to see if flush/commit happens before last pushed frame. Fast experiment • Temporarily bypass VAD: push raw frames directly to STT and let STT finalize after a short fixed delay (e.g., 300–500 ms) to confirm the missing words appear in final output. If they do, the issue is in the EoU/flush ordering. If you prefer, paste these three small snippets and I’ll point to the exact line to change: • AgentSession constructor • The loop/handler that pushes frames to VAD and STT • The code that flushes/commits and collects final STT I’ll give the minimal edit to ensure the EoU transcript is included in the final result.