my low end client device is sometimes experiencing...
# ask-ai
a
my low end client device is sometimes experiencing this error on the audio mixer:
Copy code
Dec 10 17:04:32 ato111 bash[572196]: 2025-12-10 17:04:32,469 - livekit - WARNING - AudioMixer: stream <core.audio_processor.livekit_audio_handler._MonitoringAudioStreamIterator object at 0x7f686a1a90> timeout, ignoring
Dec 10 17:04:32 ato111 bash[572196]: 2025-12-10 17:04:32,473 - livekit - WARNING - AudioMixer: stream <core.audio_processor.livekit_audio_handler._MonitoringAudioStreamIterator object at 0x7f76a4efd0> timeout, ignoring
what can be causing it and how to prevent it?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're seeing the mixer warning because an audio stream iterator failed to deliver a frame within the mixer's expected timeframe, so the mixer skips that stream temporarily. Below are the most likely causes on low-end devices and concrete steps to reduce or prevent the warnings. What causes it (likely) • The
_MonitoringAudioStreamIterator
is taking too long to yield frames (CPU or memory constrained device). • Blocking or heavy work (sync transcription, filtering, logging) inside the audio pipeline delaying frame delivery. • GC pauses or OS scheduling latency on resource-constrained hardware. • Buffer underruns when frames arrive irregularly or with large gaps. • Threading/lock contention in audio-related code (VAD, STT, monitoring) delaying the iterator. How to prevent it (practical steps) 1. Optimize the iterator ◦ Make
_MonitoringAudioStreamIterator
yield frames quickly. Move non‑essential work (analytics, logging, STT) out of the audio path to background workers or separate processes. 1. Increase buffering ◦ If you control the AudioSource, increase
queue_size_ms
(example: 1000–2000 ms) to give more headroom for transient delays. 1. Offload heavy processing ◦ Run CPU‑intensive tasks on different threads/processes or on a server rather than the client. Prefer asynchronous workers for I/O/analysis. 1. Reduce GC/allocation pressure ◦ Reuse buffers and avoid frequent allocations in the audio loop to minimize garbage collection pauses. 1. Prioritize audio threads ◦ Where supported, raise thread priority for audio capture/processing so scheduling delays are reduced. 1. Detect and recover ◦ Add monitoring around the iterator to detect stalls and restart/reset the stream when it stops producing frames for a short interval. 1. Monitor device resources ◦ Measure CPU, memory, and I/O while reproducing the issue. If CPU is pegged, reduce concurrent features (VAD, STT, heavy effects) on low-end devices. If you'd like, tell me: • which platform/language the client runs (e.g., Python, JS, Android), and • whether
_MonitoringAudioStreamIterator
does additional work (VAD, STT, heavy logging), and I’ll suggest specific code changes or an example configuration (e.g., how to set
queue_size_ms
) you can try. Sources: Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | Resolving &#34;InvalidState - failed to capture frame&#34; errors in AudioSource | client-sdk-js | livekit/livekit_composite | DeepWiki
a
how can i set queue_size_ms?
t
Which platform are you using (Python, JavaScript, Android, iOS)? I can provide the exact code example for setting
queue_size_ms
once I know your client SDK.
a
and i run python in a raspberry pi zero 2 w
t
You're on Python on a Raspberry Pi Zero 2 W — good. To increase the audio buffer, set
queue_size_ms
when you create the
AudioSource
. Example:
Copy code
from livekit import rtc

audio_source = rtc.AudioSource(
    sample_rate=24000,
    num_channels=1,
    queue_size_ms=2000  # 2000 ms = 2 seconds buffer
)
Start with
queue_size_ms=2000
and lower it if latency becomes a problem. If you want, tell me your current sample rate and any processing (VAD/STT) running on the Pi and I’ll suggest an optimal value and further tweaks. Sources: Resolving &#34;InvalidState - failed to capture frame&#34; errors in AudioSource
a
SAMPLE_RATE = 48000 BLOCKSIZE = 1920 # 40ms buffer (same as LiveKit example repo)
t
You're using 48 kHz with a 1920-sample block (40 ms). Given the Pi Zero 2 W's limited CPU, increase
queue_size_ms
to give the audio pipeline headroom for transient delays. Recommended starting values and rationale • Start with
queue_size_ms = 2000
(2 seconds). This absorbs multiple 40 ms blocks and helps prevent timeouts on spikes. • If latency is critical, try 1000 ms and test; if timeouts continue, raise back toward 2000–3000 ms. • Very large buffers (>3000 ms) increase latency noticeably, so avoid unless necessary. Python example (48 kHz, 1 channel)
Copy code
from livekit import rtc

audio_source = rtc.AudioSource(
    sample_rate=48000,
    num_channels=1,
    queue_size_ms=2000
)
Additional tips for your config • Keep per-frame work minimal in the audio path; offload VAD/STT/analysis to background threads or another process. • Reuse buffers to reduce GC pauses. • Monitor CPU while testing; if CPU is high, reduce concurrent processing or increase queue_size_ms. • If you still get intermittent timeouts, add a short watchdog that restarts the iterator when it stalls. Want a tuned suggestion? Tell me whether you run VAD/STT on-device and how sensitive your app is to end-to-end latency.
a
but the timeout is on the audio mixer for received stream, what is the capacity referring to:
Copy code
def __init__(
        self,
        sample_rate: int,
        num_channels: int,
        *,
        blocksize: int = 0,
        stream_timeout_ms: int = 100,
        capacity: int = 100,
    ) -> None:
        """
        Initialize the AudioMixer.

        The mixer accepts multiple async audio streams and mixes them into a single output stream.
        Each output frame is generated with a fixed chunk size determined by the blocksize (in samples).
        If blocksize is not provided (or 0), it defaults to 100ms.

        Each input stream is processed in parallel, accumulating audio data until at least one chunk
        of samples is available. If an input stream does not provide data within the specified timeout,
        a warning is logged. The mixer can be closed immediately
        (dropping unconsumed frames) or allowed to flush remaining data using end_input().

        Args:
            sample_rate (int): The audio sample rate in Hz.
            num_channels (int): The number of audio channels.
            blocksize (int, optional): The size of the audio block (in samples) for mixing. If not provided,
                defaults to sample_rate // 10.
            stream_timeout_ms (int, optional): The maximum wait time in milliseconds for each stream to provide
                audio data before timing out. Defaults to 100 ms.
            capacity (int, optional): The maximum number of mixed frames to store in the output queue.
                Defaults to 100.
        """
t
You're correct that the mixer warning is about a received stream timing out. Here's what
capacity
means and which settings matter for that timeout — plus practical recommendations for your Pi Zero 2 W. What
capacity
is •
capacity
is the maximum number of mixed frames the mixer will hold in its output queue. It controls how many already-mixed frames can be buffered waiting for downstream consumers (playback, encoder, network). It does not affect how long the mixer waits for each input stream to produce audio. Which parameters affect the timeout you see • `stream_timeout_ms`: the per-input wait time before the mixer logs "stream ... timeout, ignoring". Increase this to allow slow/late input streams more time (e.g., 500–1000 ms on a Pi Zero 2 W). • `blocksize`: determines the frame size (in samples) the mixer expects per mixed output. Set this to match your input block size (1920 samples at 48 kHz = 40 ms) so mixing aligns with input frame cadence. •
queue_size_ms
(on the AudioSource side): increases input buffering at the capture/source to smooth transient delays. Practical recommendations for your setup (48 kHz, 1920 block = 40 ms) • Keep
blocksize=1920
so the mixer generates frames every 40 ms. • Increase
stream_timeout_ms
to 500–1000 ms to avoid spurious timeouts from transient delays. • Increase
queue_size_ms
on the sender to 1000–2000 ms to give the capture path headroom. •
capacity
can stay at the default (100) unless downstream consumers are slow; increase it only if you observe the output queue filling and dropping frames — larger
capacity
increases memory and latency but can help if downstream is occasionally blocked. • Minimize per-frame processing (VAD/STT) on the Pi and offload to background threads/processes to reduce input stalls. If you want, I can show the exact Python constructor call with your preferred
stream_timeout_ms
,
blocksize
, and
capacity
values. Which
stream_timeout_ms
would you like to try? Sources: Processing raw media tracks | LiveKit docs | Resolving &#34;InvalidState - failed to capture frame&#34; errors in AudioSource
a
what is the queue_size_ms of the sender?
t
The sender's
queue_size_ms
is the amount of audio (in milliseconds) the local
AudioSource
will buffer before sending to the WebRTC stack. It smooths out brief delays in capture/processing on the sender and helps prevent "failed to capture frame" / input stalls on low-end devices. Key points: • It is specified when creating the
AudioSource
in Python (no global setter). • Minimum is 10 ms. • There is no single fixed default in this context; you should set it explicitly for constrained devices. • Recommended starting values for a Raspberry Pi Zero 2 W: 1000–2000 ms (2s is a common starting point). Larger values increase latency but reduce dropped frames. Example (48 kHz, single channel):
Copy code
from livekit import rtc

audio_source = rtc.AudioSource(
    sample_rate=48000,
    num_channels=1,
    queue_size_ms=2000
)
Set it to 1000 ms if you need lower latency and to 2000 ms if you need more buffering for reliability. Sources: Resolving &#34;InvalidState - failed to capture frame&#34; errors in AudioSource
a
but if the timeout is on the mixer of received audio (publish by the agent), i should config this in the agent?
t
Yes — because the timeout is logged by the receiver's AudioMixer when it doesn't get frames from an input stream in time, you should configure both sides: • On the publisher (agent) — increase the sender buffer so frames are available despite CPU or network jitter:
Copy code
audio_source = rtc.AudioSource(
      sample_rate=48000,
      num_channels=1,
      queue_size_ms=2000
  )
Use 1000–2000 ms on a Raspberry Pi Zero 2 W (start at 2000 ms). • On the receiver (where the AudioMixer runs) — increase the mixer timeout so it waits longer for late streams and set blocksize to match the sender:
Copy code
mixer = AudioMixer(
      sample_rate=48000,
      num_channels=1,
      blocksize=1920,         # 40 ms at 48 kHz
      stream_timeout_ms=500,  # try 500–1000 ms
      capacity=100
  )
Why both: • The sender's
queue_size_ms
smooths capture/processing jitter so frames arrive more regularly. • The mixer's
stream_timeout_ms
controls how long the receiver waits before ignoring a late input. •
blocksize
should match the sender's chunk size to align mixing cadence. •
capacity
only controls output buffering and is not the cause of input timeouts. If you want, tell me which side you control (agent, receiver, or both) and I’ll suggest concrete values to try and a short test plan.
a
i don't see where to change the queue size ms of the agent
t
You set
queue_size_ms
in the publisher (agent) code when you create the
AudioSource
used to capture/send audio. It's part of the AudioSource constructor in Python and must be changed in the agent's codebase (the process that captures audio and publishes it). Example (agent code):
Copy code
from livekit import rtc

audio_source = rtc.AudioSource(
    sample_rate=48000,
    num_channels=1,
    queue_size_ms=2000  # <-- set buffer here on the agent
)

# use audio_source when creating the track / publisher
track = rtc.LocalAudioTrack(audio_source=audio_source)
# ... publish track to the room ...
Where to change it in your project • Find the file that constructs the capture/audio source or creates the LocalAudioTrack on the agent side. • Replace or add
queue_size_ms=<ms>
in the
rtc.AudioSource(...)
call. Notes • Pick 1000–2000 ms for a Raspberry Pi Zero 2 W (start with 2000 ms). • This setting lives on the sender; increasing it reduces capture stalls and makes frames available to the network/mixer more consistently. If you tell me the agent file or snippet that creates the audio source/track, I can show the exact edit.
a
but in the LiveKit Cloud Agent. isn't this abstracted away?
t
Short answer: Yes — you must set
queue_size_ms
in the Cloud Agent code that runs on the publisher (the agent process). LiveKit Cloud does not auto-tune sender-side audio buffers for constrained hardware. What to change (agent / publisher) • Locate where the agent creates the AudioSource / LocalAudioTrack. • Add
queue_size_ms
to the AudioSource constructor. Example for your setup (48 kHz, 1920 blocksize):
Copy code
from livekit import rtc

audio_source = rtc.AudioSource(
    sample_rate=48000,
    num_channels=1,
    queue_size_ms=2000  # increase buffer for Pi Zero 2 W
)

track = rtc.LocalAudioTrack(audio_source=audio_source)
# publish the track as you already do
Why this matters •
queue_size_ms
is the sender-side buffer (ms of audio) that smooths capture/processing jitter. Increasing it prevents the agent from starving the receiver/mixer when the Pi is under load. • The mixer timeout you saw is on the receiver side when it doesn't get frames in time; increasing sender buffering and ensuring non-blocking capture reduces those timeouts. Recommended next steps 1. Update the agent code to set
queue_size_ms=2000
. 2. Keep
blocksize=1920
on both sides and raise
stream_timeout_ms
on the receiver to 500–1000 ms if you still see warnings. 3. Monitor CPU and logs for "failed to capture frame" or mixer timeouts; if still frequent, try 3000 ms or offload heavy tasks from the capture loop. If you want, paste the agent file that creates the AudioSource/LocalAudioTrack and I’ll show the exact edit. Sources: Resolving &#34;InvalidState - failed to capture frame&#34; errors in AudioSource | Bringing Zoom&#39;s end-to-end optimizations to WebRTC | External data and RAG | LiveKit Docs | Camera & microphone | LiveKit docs | Capturing the First Few Seconds of a Call for Processing