able-jackal-84140
07/10/2025, 8:37 AMbackground_audio = BackgroundAudioPlayer(
# play office ambience sound looping in the background
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
# play keyboard typing sound when the agent is thinking
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
tall-airline-16756
07/10/2025, 8:37 AMtall-airline-16756
07/10/2025, 8:38 AMBackgroundAudioPlayer
background sound is triggered automatically based on the agent's state changes:
• Ambient sounds start looping as soon as the player is started and play continuously in the background.
• Thinking sounds are triggered whenever the agent enters the "thinking" state, typically during function tool execution, but also whenever you manually signal this state.
You do not need function tools to use BackgroundAudioPlayer
. It can be used on its own for just background audio, or you can explicitly call its play
method to trigger sounds manually as needed. However, if you use it alongside function tools, the agent will automatically play the thinking sound whenever a function is running.
To use the player, create and configure it as shown in your example, then start it after initiating your room and agent session:
await background_audio.start(room=ctx.room, agent_session=session)
The player handles lifecycle integration, so ambient and thinking sounds are triggered at the right times. For on-demand sounds, you can always use:
background_audio.play("/path/to/custom-sound.mp3")
For more details, see guidelines on ambient and thinking sound control in the knowledge base.
Sources: livekit-agents/livekit/agents/__init__.py | Agent speech and audio | LiveKit Docs | Handling RAG Delays in Voice Agents | LiveKit Docs