rust-sdks icon indicating copy to clipboard operation
rust-sdks copied to clipboard

Capture frame failed

Open vuleetu opened this issue 1 year ago • 2 comments

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

vuleetu avatar Nov 28 '24 09:11 vuleetu

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?

btakita avatar Jan 29 '25 01:01 btakita

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

boyko11 avatar Apr 17 '25 12:04 boyko11

I am facing the exact same issue. TTS is lost but text transmission continues. Why is this marked as Not planned?

vishnukool avatar Oct 24 '25 02:10 vishnukool

I think this was closed automatically due to inactivity, but I’ll reopen it since it appears that this issue persists.

ladvoc avatar Oct 24 '25 02:10 ladvoc

@vishnukool, would you mind sharing what version of the agents framework you are using?

ladvoc avatar Oct 24 '25 02:10 ladvoc

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"}

vishnukool avatar Oct 24 '25 02:10 vishnukool

OK returning the favor to the world. This got fixed by updating livekit agents to latest - livekit-agents 1.2.15

vishnukool avatar Oct 24 '25 04:10 vishnukool

That's good to hear, thank you for confirming!

ladvoc avatar Oct 24 '25 06:10 ladvoc