microscopic-dress-75199
10/09/2025, 8:35 PMtall-airline-16756
10/09/2025, 8:35 PMtall-airline-16756
10/09/2025, 8:35 PMmicroscopic-dress-75199
10/09/2025, 8:36 PMtall-airline-16756
10/09/2025, 8:36 PMBackgroundAudioPlayer instance right in your entrypoint function. You can set it up with some lovely ambient or thinking sounds by using AudioConfig objects. Once that’s done, just start it with your room and agent session.
Here’s a simple example to guide you:
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),
],
)
await background_audio.start(room=ctx.room, agent_session=session)
If you’d like to dive deeper or see a full example, feel free to check out the Background Audio Example on GitHub. I’m here if you have any questions along the way!
Sources: Agent speech and audio | LiveKit Docs | examples/drive-thru/drivethru_agent.pymicroscopic-dress-75199
10/09/2025, 8:37 PMtall-airline-16756
10/09/2025, 8:37 PMBackgroundAudioPlayer instance you create in the entrypoint function doesn’t actually need to be passed to the agent. It works on its own and gets started with the room and agent session using this line:
await background_audio.start(room=ctx.room, agent_session=session)
This way, the audio stays perfectly in sync with the agent’s lifecycle. Now, if you ever want your agent to trigger custom audio playback directly, you could set it up to accept the BackgroundAudioPlayer, but for most standard uses, that’s not necessary. I hope this helps clear things up!
Sources: examples/drive-thru/drivethru_agent.py | Agent speech and audio | LiveKit Docsmicroscopic-dress-75199
10/09/2025, 8:38 PMtall-airline-16756
10/09/2025, 8:38 PMBackgroundAudioPlayer. Here's a simple way to get started:
1. First, create the player with your choice of ambient and/or 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),
],
)
2. Next, start the player with the room and agent session like this:
await background_audio.start(room=ctx.room, agent_session=session)
3. And if you'd like to play audio on-demand, you can use the play() method:
await background_audio.play("filepath.ogg", loop=True)
This way, you can add extra audio files or sound effects during your session. If you'd like to see everything put together, feel free to check out the Background Audio example. I'm here if you have any questions along the way!
Sources: examples/drive-thru/drivethru_agent.py | docs/index.yaml | Agent speech and audio | LiveKit Docsmicroscopic-dress-75199
10/09/2025, 8:51 PMtall-airline-16756
10/09/2025, 8:53 PMBackgroundAudioPlayer in Python. This player is great because it automatically syncs with the agent's "thinking" state, which happens during tool calls, including MCP calls. Here's a simple way to get it set up:
1. First, configure the player with a "thinking" sound like this:
background_audio = BackgroundAudioPlayer(
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
2. Then, start the player with the room and agent session:
await background_audio.start(room=ctx.room, agent_session=session)
3. Once set up, the "thinking" sound will play automatically during tool execution. If you'd like to play audio manually during specific moments, you can use this:
await background_audio.play("path/to/sound.ogg", loop=False)
If you're interested in more customization, like adding verbal prompts before the sound, you can override the llm_node function to detect tool calls and trigger extra actions. Just let me know if you'd like me to share an example of that—I’m here to help!
Sources: Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | agent.py | docs/index.yaml | External data and RAG | LiveKit Docsmicroscopic-dress-75199
10/09/2025, 8:56 PMtall-airline-16756
10/09/2025, 8:56 PMBackgroundAudioPlayer takes care of playing these sounds only when the agent is in the "thinking" state and stops right after, so there’s no overlapping or extra noise.
If this isn’t quite working for you, no worries! You have a couple of options:
• You can turn off the thinking sound by setting thinking_sound=None when you create the player.
• Or, you might prefer using other ways to keep users informed, like verbal prompts (for example, "Let me look that up...") or visual cues in the UI.
Rest assured, the system is built to handle these sounds safely, so you won’t run into issues like audio clipping or slowdowns. If you'd like, I’m here to help you tweak this behavior to fit your needs perfectly!
Sources: External data and RAG | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Agent speech and audio | LiveKit Docs | delay-handling/README.mdoc | Web and mobile frontends | LiveKit Docs