chilly-nest-87883
07/23/2025, 12:40 AMWARNING livekit.agents - _SegmentSynchronizerImpl text marked as ended in capture text, rotating segment
Cascading to these errors:
2025-07-22 17:24:54,862 - ERROR livekit.agents - Error in _audio_forwarding_task
Traceback (most recent call last):
File "/Users/clovishublin/Desktop/mirror-repos/livekit-agent-service/venv/lib/python3.9/site-packages/livekit/agents/utils/log.py", line 16, in
async_fn_logs
return await fn(*args, **kwargs)
File "/Users/clovishublin/Desktop/mirror-repos/livekit-agent-service/venv/lib/python3.9/site-packages/livekit/agents/voice/generation.py", line
302, in _audio_forwarding_task
await audio_output.capture_frame(frame)
File "/Users/clovishublin/Desktop/mirror-repos/livekit-agent-service/venv/lib/python3.9/site-packages/livekit/agents/voice/transcription/synchroni
zer.py", line 498, in capture_frame
await self._next_in_chain.capture_frame(frame) # passthrough audio
File "/Users/clovishublin/Desktop/mirror-repos/livekit-agent-service/venv/lib/python3.9/site-packages/livekit/agents/voice/room_io/_output.py",
line 83, in capture_frame
await self._audio_source.capture_frame(frame)
File "/Users/clovishublin/Desktop/mirror-repos/livekit-agent-service/venv/lib/python3.9/site-packages/livekit/rtc/audio_source.py", line 149, in
capture_frame
raise Exception(cb.capture_audio_frame.error)
Exception: an RtcError occured: InvalidState - failed to capture frame
2025-07-22 17:24:54,935 - WARNING livekit.agents - _SegmentSynchronizerImpl audio marked as ended in capture audio, rotating segment
2025-07-22 17:24:54,937 - ERROR livekit.agents - capture_frame called while flush is in progresstall-airline-16756
07/23/2025, 12:41 AMtall-airline-16756
07/23/2025, 12:43 AMInvalidState - failed to capture frame typically occurs when the rtc.AudioSource queue is overloaded. To address this, increase the queue_size_ms parameter when creating your AudioSource instance. For example:
audio_source = rtc.AudioSource(
sample_rate=sample_rate,
num_channels=channels,
queue_size_ms=2000 # Increase from default to prevent frame capture failures
)
Larger queue_size_ms values (such as 1000-2000ms) provide more buffer room and help prevent frame capture failures.
LiveKit's TTS architecture is designed for each agent to maintain its own TTS processing pipeline. Sharing TTS resources across multiple agents is not a standard pattern and could introduce conflicts or resource contention, but this is not directly cited as a cause of the errors or warnings you've described.
To resolve the jerky speech and related errors, focus on increasing the audio buffer size as shown above. If you are sharing TTS resources between agents, consider isolating TTS pipelines per agent to avoid potential conflicts.
Sources: Speech & Audio Processing | livekit/livekit_composite | DeepWiki | Resolving "InvalidState - failed to capture frame" errors in AudioSource | livekit-agents/livekit/agents/voice/agent_session.pychilly-nest-87883
07/23/2025, 2:39 AMtall-airline-16756
07/23/2025, 2:40 AMqueue_size_ms parameter. It's actually configured right when you create your rtc.AudioSource instance, not through session.start(). Think of it like setting up your audio buffer before hitting the road.
Here's a quick example to show you:
audio_source = rtc.AudioSource(
sample_rate=sample_rate,
num_channels=channels,
queue_size_ms=2000 # Set buffer size here
)
Just a heads up ā there's no queue_size_ms or audio_source option in session.start(). Make sure you set up your AudioSource with the buffer size you want before kicking off your session.
Pro tip: We usually recommend setting queue_size_ms between 1000-2000ms. This helps keep your audio streaming smooth and prevents those annoying frame capture hiccups. š
Sources: livekit-rtc/livekit/rtc/audio_source.py | livekit-agents/livekit/agents/voice/agent_session.py | Resolving "InvalidState - failed to capture frame" errors in AudioSourcechilly-nest-87883
07/23/2025, 2:41 AMaudio_source = AudioSource(
sample_rate=24000, # Match TTS provider sample rate
num_channels=1,
queue_size_ms=2000 # Increase from default ~500ms to prevent buffer overrun
)
<http://logger.info|logger.info>(f"[{session_id}] :loud_sound: Configured AudioSource with 2000ms queue buffer to prevent frame capture failures")
try:
await session.start(
room=ctx.room,
agent=agent,
audio_source=audio_source, # Add the configured AudioSource
room_input_options=room_input_options,
room_output_options=RoomOutputOptions(
sync_transcription=True,
),tall-airline-16756
07/23/2025, 2:43 AMchilly-nest-87883
07/23/2025, 2:52 AM