colossal-lock-10836
08/29/2025, 2:10 PMtall-airline-16756
08/29/2025, 2:10 PMtall-airline-16756
08/29/2025, 2:11 PMBackgroundAudioPlayer
from the LiveKit Agents Python SDK. Here’s a simple way to set it up:
1. First, initialize the BackgroundAudioPlayer
in your agent’s entrypoint function:
background_audio = BackgroundAudioPlayer()
1. Then, start the audio player once you’ve connected to the room and initialized the session:
await background_audio.start(room=ctx.room, agent_session=session)
1. Now, play the ring sound for 2 seconds like this:
handle = background_audio.play("/path/to/ring-sound.mp3")
await asyncio.sleep(2) # Just wait for 2 seconds
handle.stop() # And stop the playback
If your audio file is exactly 2 seconds long, you can also just let it play through completely:
await background_audio.play("/path/to/ring-2-sec.aac")
Just make sure the audio file is accessible to your agent server and is in a format that works well (like MP3, AAC, or OGG). If you run into any questions or need a hand with anything else, feel free to ask—I'm here to help!
Sources: solutions/doorbell_demo/README.md | agent_extensions/agent_extensions/utils/wav_player.py | Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/chat_cli.pycolossal-lock-10836
08/29/2025, 2:16 PMtall-airline-16756
08/29/2025, 2:17 PMBackgroundAudioPlayer
class from the Python SDK. Here’s a quick guide to get you started:
1. First, initialize the BackgroundAudioPlayer
with your custom thinking sound:
from livekit.agents import BackgroundAudioPlayer
background_audio = BackgroundAudioPlayer(
thinking_sound="/path/to/your/custom-thinking-sound.mp3"
)
1. Then, start the player right after you initialize the agent session:
await background_audio.start(room=ctx.room, agent_session=session)
Once set up, your custom thinking sound will play automatically whenever the agent is in the "thinking" state (like when it’s processing or making tool calls).
Oh, and if you want to mix things up, you can even use multiple custom thinking sounds with different probabilities like this:
from livekit.agents import AudioConfig
background_audio = BackgroundAudioPlayer(
thinking_sound=[
AudioConfig("/path/to/sound1.mp3", volume=0.8, probability=0.6),
AudioConfig("/path/to/sound2.ogg", volume=0.7, probability=0.4),
]
)
If you have any questions or want a hand with anything else, just let me know—I’m here to help!
Sources: Agent speech and audio | LiveKit Docs