if we use preamble phrases, does the agent goes in...
# ask-ai
a
if we use preamble phrases, does the agent goes into thinking or speaking?
Copy code
Tool 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?
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.
When the Realtime model moves into a "thinking" state after those initial preamble phrases—like when it needs to call tools or do some extra processing—you might hear a thinking sound (think keyboard typing) if you’ve set up the
BackgroundAudioPlayer
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.py
a
if i have an background audio player, i need to subscribe to another audio track right?
t
The
BackgroundAudioPlayer
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__.py
a
but from a client perspective, how should i handle the agent and thinking sound tracks? right now it makes the agent sound robotic
t
To keep your audio sounding natural and avoid that robotic vibe, here’s a friendly way to handle agent and thinking sound tracks: • Use BackgroundAudioPlayer: Set it up with ambient and thinking sounds (like typing) that match what the agent is doing. The player will take care of playing and stopping these sounds automatically when the agent’s state changes, such as when it’s “thinking.” • Clean Up LLM Output: Before sending text to the TTS engine, make sure to remove any internal tokens (like
<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 Docs
a
when adding the background player, the pitch sounds slow down an robotic from the agent
t
Hey there! If you’re noticing pitch slowdowns or robotic sounds when using
BackgroundAudioPlayer
, 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&#39;s end-to-end optimizations to WebRTC | Bringing Zoom&#39;s end-to-end optimizations to WebRTC | Bringing Zoom&#39;s end-to-end optimizations to WebRTC
a
what is the sample rate of the received audio and the sample size? it's only slowed down and robotic when using the background player do i need to handle an audio track different than the agent one?