big-controller-60015
11/07/2025, 3:08 PMtall-airline-16756
11/07/2025, 3:08 PMtall-airline-16756
11/07/2025, 3:09 PMBackgroundAudioPlayer class from the livekit.agents.voice module. Here's a simple example to get you started:
from livekit.agents import BackgroundAudioPlayer, BuiltinAudioClip, AudioConfig
from livekit.plugins import openai
# Initialize player with ambient and thinking sounds
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
# Start the player in a room and agent session
await background_audio.start(room=ctx.room, agent_session=session)
If you'd like to use your own custom audio files, no worries! Just provide the file paths like this:
import os
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(
str(os.path.join(os.path.dirname(__file__), "bg_noise.mp3")),
volume=1.0,
),
)
Just remember to call start() after your room connection and agent session have started. If you have any questions or want to explore more about supported audio sources and configurations, please feel free to ask—I’m here to help!
Sources: examples/voice_agents/background_audio.py | complex-agents/drive-thru/session_setup.py | Agent speech and audio | LiveKit docs | Agent speech and audio | LiveKit docs