Hey team. I'm investigating an issue where the bac...
# ask-ai
p
Hey team. I'm investigating an issue where the background sound plays for 3 seconds when the agent is thinking, then goes silent. I thought it would keep playing (in a loop) until the agent transitions out of the "thinking" state. Did I miss anything?
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you reached out about the background sound during the "thinking" state! This is managed by the
BackgroundAudioPlayer
class. Typically, the sound is set up to loop continuously until the agent moves out of the "thinking" state. If you’re noticing that the sound stops after about 3 seconds, it might be related to how the audio source is configured. To help you get that smooth, uninterrupted playback, here are a few things to check: • If your audio source is a file path, make sure the
loop
parameter is set to
True
. • If you’re using an
AsyncIterator
for custom audio frames, just double-check that the looping logic is handled properly on your end. • Also, take a look at the
AudioConfig
and see if the total probability is less than 1.0 — this can sometimes cause the sound to drop out unexpectedly. If you’d like to explore more or see some examples, the Background Audio example in the LiveKit Agents repository is a fantastic resource. Sources: Agent speech and audio | LiveKit Docs | examples/voice_agents/background_audio.py | Web and mobile frontends | LiveKit Docs
p
I don't control the sound; it's played by livekit automatically when the agent enters the thinking state.
t
Thanks for reaching out! By default, LiveKit doesn’t play any background sound during the "thinking" state unless a specific
thinking_sound
configuration has been set. So, if you’re hearing a sound for about 3 seconds, it likely means there’s a custom setting in your environment. To help you better, could you please check if any custom
thinking_sound
configuration has been applied on your end? If not, it might be a good idea to connect with your development team or take a look at the agent’s initialization code to see if there are any preset audio settings. I’m here to help you through this! Sources: External data and RAG | LiveKit Docs | livekit-plugins/livekit-plugins-gladia/livekit/plugins/gladia/stt.py | Agent speech and audio | LiveKit Docs
p
it has, like this:
Copy code
background_audio = BackgroundAudioPlayer(
        # play office ambience sound looping in the background
        ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
        # play keyboard typing sound when the agent is thinking
        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)
t
Thank you so much for sharing your configuration! What you're seeing is actually expected because the
thinking_sound
in
BackgroundAudioPlayer
is designed to play just once each time the state changes—it doesn’t loop automatically. This makes sense since the sound is tied to the agent’s lifecycle, playing when the agent enters the "thinking" state and stopping as soon as the state changes. If you’d like the sound to loop continuously while in the "thinking" state, you’d need to add some custom logic. For instance, you could manually use the
play()
method with a file path and set
loop=True
. Just keep in mind that this means you’d be managing playback separately from the automatic
thinking_sound
behavior. Please feel free to reach out if you’d like me to walk you through how to set that up or if you have any other questions—I’m here to help! Sources: Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/background_audio.py