able-jackal-19719
09/08/2025, 7:08 AMtall-airline-16756
09/08/2025, 7:08 AMtall-airline-16756
09/08/2025, 7:09 AMBackgroundAudioPlayer 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:
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