Capture frame failed
I found a lot ofRtcError errors in worker logs.
Nov 28 01:57:50 python[117393]: await self._audio_source.capture_frame(frame)
Nov 28 01:57:50 python[117393]: File "/home/ubuntu/miniconda3/envs/chat/lib/python3.12/site-packages/livekit/rtc/audio_source.py", line 152, in capture_frame
Nov 28 01:57:50 python[117393]: raise Exception(cb.capture_audio_frame.error)
Nov 28 01:57:50 python[117393]: Exception: an RtcError occured: InvalidState - failed to capture frame {"pid": 121680, "job_id": "AJ_oHY4vMyQc8kr"}
Transcriptions were streamed to client normally, but TTS were lost. I need help to figure out how to avoid this issue
I'm also getting this error when streaming audio after the room opens. Is there any chance that the error message can provide more detail in what state is invalid?
After I dug down to the Rust code: https://github.com/livekit/rust-sdks/blob/0773bcec4e24812b382e71166b2ab359bf1a9384/libwebrtc/src/native/audio_source.rs#L87
and with some LLM help, I was able to alleviate the issue in our python code by doubling the size of the queue_size_ms:
audio_source = rtc.AudioSource(
sample_rate=<our_sample_rate>,
num_channels=<our_num_channels>,
queue_size_ms=2000
I was able to reproduce it fairly consistently by setting the queue_size_ms to min allowed value of 10
I am facing the exact same issue. TTS is lost but text transmission continues. Why is this marked as Not planned?
I think this was closed automatically due to inactivity, but I’ll reopen it since it appears that this issue persists.
@vishnukool, would you mind sharing what version of the agents framework you are using?
Yes, it's happening unfortunately and really annoying since on long stories voice just stops. We use below
livekit-agents[google,anthropic,silero,turn-detector,openai,cartesia,deepgram,elevenlabs]~=1.0.23
ANd below is the error log
{"message": "Error in _audio_forwarding_task\nTraceback (most recent call last):\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/generation.py\", line 237, in _audio_forwarding_task\n await audio_output.capture_frame(f)\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/transcription/synchronizer.py\", line 487, in capture_frame\n await self._next_in_chain.capture_frame(frame) # passthrough audio\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/room_io/_output.py\", line 78, in capture_frame\n await self._audio_source.capture_frame(frame)\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/rtc/audio_source.py\", line 142, in capture_frame\n cb: proto_ffi.FfiEvent = await queue.wait_for(\n ^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/rtc/_utils.py\", line 81, in wait_for\n event = await self.get()\n ^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/asyncio/queues.py\", line 158, in get\n await getter\nasyncio.exceptions.CancelledError\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/generation.py\", line 251, in _audio_forwarding_task\n await audio_output.capture_frame(frame)\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/transcription/synchronizer.py\", line 487, in capture_frame\n await self._next_in_chain.capture_frame(frame) # passthrough audio\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/voice/room_io/_output.py\", line 78, in capture_frame\n await self._audio_source.capture_frame(frame)\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/rtc/audio_source.py\", line 149, in capture_frame\n raise Exception(cb.capture_audio_frame.error)\nException: an RtcError occured: InvalidState - failed to capture frame", "level": "ERROR", "name": "livekit.agents", "pid": 213, "job_id": "AJ_UtLmTe5439Hx", "timestamp": "2025-10-22T19:09:32.832086+00:00"}
OK returning the favor to the world. This got fixed by updating livekit agents to latest - livekit-agents 1.2.15
That's good to hear, thank you for confirming!