how to play a "ring" sound for two seconds after a...
# ask-ai
c
how to play a "ring" sound for two seconds after agent initializes in beginning of each session
t
Thanks for reaching out, ZaidKaraymeh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to play a ring sound for two seconds right after an agent starts at the beginning of each session, you can easily do this using the
BackgroundAudioPlayer
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:
Copy code
background_audio = BackgroundAudioPlayer()
1. Then, start the audio player once you’ve connected to the room and initialized the session:
Copy code
await background_audio.start(room=ctx.room, agent_session=session)
1. Now, play the ring sound for 2 seconds like this:
Copy code
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:
Copy code
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.py
c
how to add custom thinking sound
t
Hey there! If you want to add a custom thinking sound in LiveKit, you can easily do that using the
BackgroundAudioPlayer
class from the Python SDK. Here’s a quick guide to get you started: 1. First, initialize the
BackgroundAudioPlayer
with your custom thinking sound:
Copy code
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:
Copy code
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:
Copy code
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