how to set multiple background audio agent
# ask-ai
a
how to set multiple background audio agent
t
Thanks for reaching out, affandy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Setting up multiple background audio sources in LiveKit is pretty straightforward! You can use just one
BackgroundAudioPlayer
instance and load it with different audio clips. This way, you get smooth and flexible control over your background sounds. Here’s a simple way to do it: 1. For ambient sounds, pass a list of
AudioConfig
objects to the
ambient_sound
parameter. Each one can have its own sound, volume, and chance of playing. 2. For thinking sounds, give a list of
AudioConfig
objects to the
thinking_sound
parameter. These will play whenever the agent enters the “thinking” state. Here’s an example to get you started:
Copy code
background_audio = BackgroundAudioPlayer(
    ambient_sound=[
        AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8, probability=0.7),
        AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.6, probability=0.3),
    ],
    thinking_sound=[
        AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
        AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
    ],
)

await background_audio.start(room=ctx.room, agent_session=session)
This way, one
BackgroundAudioPlayer
handles all your audio needs smoothly. If you’re thinking about running multiple separate audio players or have something else in mind, just let me know—I’m here to help! Sources: Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs