aloof-scooter-47164
09/08/2025, 8:58 PMTool Call Preambles
Some use cases could benefit from the Realtime model providing an audio response at the same time as calling a tool. This leads to a better user experience, masking latency. You can modify the sample phrase to provide.
and could we use a thinking sound after the preamble phrase ended? how could we detect that?tall-airline-16756
09/08/2025, 8:58 PMtall-airline-16756
09/08/2025, 8:59 PMBackgroundAudioPlayer with a thinking_sound. This sound plays until the agent starts talking or finishes its reasoning and tool work.
The system makes it easy by automatically playing the thinking sound right when the agent switches to the "thinking" state—that’s right after the preamble ends and just before any tool calls or extra processing kick in.
Sources: models/templates/CohereForAI-c4ai-command-r7b-12-2024-tool_use.jinja | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pyaloof-scooter-47164
09/08/2025, 9:54 PMtall-airline-16756
09/08/2025, 9:55 PMBackgroundAudioPlayer is pretty handy because you don’t need to subscribe to any extra audio streams. It takes care of managing and sharing its own audio track right in the room. Plus, if you set it up with a thinking_sound, it’ll automatically play that sound (like keyboard typing) whenever the agent is in the "thinking" state. It also handles ambient sounds all on its own, playing them on a loop, so you don’t have to worry about subscribing to anything else.
Sources: Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/__init__.pyaloof-scooter-47164
09/08/2025, 10:05 PMtall-airline-16756
09/08/2025, 10:05 PM<tool_call>). You can do this easily using the before_tts_cb callback or by customizing the llm_node method.
• Boost Client-Side Experience: Keep an eye on the agent’s state (like “thinking” or “speaking”) and sync up audio or visual cues to make everything feel smooth and responsive.
Following these tips will help you create a more natural and engaging experience that users will really appreciate.
Sources: Modifying LLM output before TTS | LiveKit Docs | agent_extensions/agent_extensions/rag/handler.py | Web and mobile frontends | LiveKit Docs | pipeline-llm/replacing_llm_output.py | Web and mobile frontends | LiveKit Docsaloof-scooter-47164
09/08/2025, 10:29 PMtall-airline-16756
09/08/2025, 10:30 PMBackgroundAudioPlayer, it’s usually because the audio pipeline is a bit congested or the buffer size is too small. No worries though—here are some friendly tips to help you fix that:
• Increase Buffer Size: The default buffer size is 400ms, which might cause some frame capture hiccups. If you can, try bumping it up to 1000–2000ms for smoother playback.
• Use Optimized Audio Files: Make sure your audio files are in Opus/OGG or MP3 format, sampled at 48kHz mono. This helps avoid any annoying delays from real-time transcoding.
• Minimize Overlapping Sounds: Try to set up your thinking_sound and ambient_sound so they don’t play over each other too much. Too many sounds at once can overwhelm the audio mixer.
• Monitor for Errors: Keep an eye on your logs for frame capture errors like "InvalidState - failed to capture frame." These are signs that the buffer might be overflowing.
• Optimize Agent Logic: If you can, reduce any delays in tasks that trigger thinking sounds—this helps cut down on audio processing load.
Give these a try, and you should notice those robotic audio glitches smoothing out and your overall sound quality getting better. If you hit any snags, I’m here to help!
Sources: examples/voice_agents/background_audio.py | Speech & Audio Processing | livekit/livekit_composite | DeepWiki | Bringing Zoom's end-to-end optimizations to WebRTC | Bringing Zoom's end-to-end optimizations to WebRTC | Bringing Zoom's end-to-end optimizations to WebRTCaloof-scooter-47164
09/09/2025, 4:03 AM