How do I play background audio continuously throug...
# agents
c
How do I play background audio continuously throughout the whole call instead of just when the agent is talking?
s
Use the
ambient_sound
option of `BackgroundAudioPlayer`: https://docs.livekit.io/agents/build/audio/#background-audio
c
yes but that only plays whe the agent is talking but not when the user is talking
I like that noise but I want it to play continuously throughou the whole session
and have the option to pause it when needed
s
It plays for the duration, not just when the agent is talking.
c
background_audio = BackgroundAudioPlayer( ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8), thinking_sound=[ AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8), AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.7), ], ) await background_audio.start(room=ctx.room, agent_session=session) above is what I am doing. I can barely hear it when the agent stops talking
like what happens is that after the agent finishes speaking, the anbient sound continues for like 1 second and then stops until the agent starts speaking again
so its like full silence in between
s
Where are you creating the player? It should be in your entry point fn or some where with a long lifetime
Is it not playing or just playing quietly?
c
it is.
Copy code
await session.start(
            agent=agent,
            room=ctx.room,
            room_options=room_io.RoomOptions(
                audio_input=room_io.AudioInputOptions(
                    noise_cancellation=noise_cancellation.BVCTelephony()
                )
            )
        )

background_audio = BackgroundAudioPlayer(
            ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
            thinking_sound=[
                AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
                AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.7),
            ],
        )
        await background_audio.start(room=ctx.room, agent_session=session)
its in my entreypoint right after session starts
its not playing at all like it stops and then it starts again when the agent starts talking. When the agent is speaking, I hear the background audio very clearly
s
If you turn off bvc can you hear it?
This audio clip has people talking. It's exactly the kind of thing bvc is meant to eliminate
c
I havent tried that.. let me try it
but ideally i would not want that because my use case is phone calls
i just wnat the audio to continue thats all. in the docs, it says it plays during the lifecycle of the agent which I assume it means it plays when the agent is actually responding. It needs to play when the room is active
Didn't work @strong-dress-64642
s
And you don't also have krisp enabled on your frontend/ inbound trunk
?
c
no I just invoke the sip endpoint
i dont think this has to do with noise cancelling because when I tell my agent to stop speaking and it stops for like 10s I hear no background audio so its clear to me its just getting paused.
if noise cancellign was an issue i dont think i would be able to hear the bckground audio clearly even when the agent is speaking but I am
s
The player literally cannot be paused and restarted, so in theory it must be playing the whole time. That's why I suspect NC
And the NC struggling while agent is talking lets you hear a little bit of the bg audio
Have you tested this in a web session instead of phone call and found the same?
c
I have not yet but I can try
I only deal with phone calls so
theres no way to pause the background audio at any time? @strong-dress-64642
s
You can destroy the player and create a new one, but no the player is not pauseable
c
I see. And is there a way to parse out that background audio in egress recordings?