rough-house-12653
09/07/2025, 1:56 PMtall-airline-16756
09/07/2025, 1:56 PMtall-airline-16756
09/07/2025, 1:56 PMBackgroundAudioPlayer class available in Python. It’s a handy way to play ambient sounds continuously or even trigger specific sounds during certain actions—pretty neat, right?
Using Built-in Sounds:
• LiveKit comes with some cool built-in audio clips like OFFICE_AMBIENCE and KEYBOARD_TYPING. You can easily use these by passing them to the BackgroundAudioPlayer.
from livekit.agents import BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
],
)
Using Custom Audio Files:
• Got your own audio files? No problem! Just provide the file paths, and they’ll loop automatically if used as ambient sound.
background_audio = BackgroundAudioPlayer(
ambient_sound="/path/to/my-custom-sound.mp3",
)
Starting the Player:
• Once you’ve set up your BackgroundAudioPlayer, just start it by calling the start() method with your room and agent session:
await background_audio.start(room=ctx.room, agent_session=session)
If you want to get a bit fancier—like fading volumes or timing things just right—you can create a custom audio handler using rtc.AudioSource and rtc.LocalAudioTrack.
And hey, if you want a full working example to follow along, check out the Background Audio Example. It’s a great resource!
Sources: Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | meditation_assistant/README.mdoc | examples/voice_agents/README.md