how is this background triggered? Can I use this w...
# ask-ai
a
how is this background triggered? Can I use this without any function tool?
Copy code
background_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),
        ],
    )
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
BackgroundAudioPlayer
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:
Copy code
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:
Copy code
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