Hi! I have a voice agent using OpenAI's realtime m...
# ask-ai
c
Hi! I have a voice agent using OpenAI's realtime model. I've set the background audio to office sounds, probability to default, and then run
agent.say()
. The problem is that the office sounds work until the user speaks for the first time, and then they cut out. The thinking sounds, however, work correctly.
t
Thanks for reaching out, Juan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you get to the bottom of this! Could you please share a bit more about how you've set things up? Specifically: • Are you using any custom configurations or tweaks to the background audio settings? • What usually happens right before the background audio stops? Any particular steps or events? • Have you noticed any error messages or logs popping up when the audio cuts out? Sources: examples/voice_agents/background_audio.py | examples/src/realtime_turn_detector.ts | Agent speech and audio | LiveKit docs
c
session init on entry point: await session.start( agent=agent, room=ctx.room, room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVCTelephony(), ), ) background_audio = BackgroundAudioPlayer( thinking_sound=[ AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8), AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7), ], ambient_sound=[ AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE,volume=0.8) ] ) await background_audio.start(room=ctx.room, agent_session=session) #print("ageeenttttt") logger.info(agent.conversationState.company_name) await session.generate_reply(instructions=build_system_prompt(agent.conversationState.company_name)) Agent init: super().__init__( instructions=build_system_prompt(self.conversationState.company_name), llm=openai.realtime.RealtimeModel(voice="coral"), vad=silero.VAD.load(), turn_detection=MultilingualModel(), )
t
Thank you so much for sharing the code snippet! To better understand what might be going on, I have a few quick questions for you: • Are you using OpenAI's built-in noise reduction, LiveKit's noise cancellation (like BVC Telephony), or maybe both? • When the user speaks, does the background audio stop right away, or is there a bit of a delay? • Have you had a chance to try turning off noise cancellation or VAD to see if the background audio still plays? Getting a bit more insight on these points will really help us figure out whether the issue is tied to audio processing or something else. I’m here to help you through this! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | complex-agents/drive-thru/session_setup.py | Enhanced noise cancellation | LiveKit docs
c
Truned down bvc and VAD, and the problem still happens
t
It sounds like the issue you're facing is related to the OpenAI Realtime model's internal turn detection, which is on by default and can sometimes interrupt background audio when it detects user speech. Even if noise cancellation and VAD are turned off, this turn detection might still impact your audio playback. A helpful way to fix this is by disabling turn detection in your RealtimeModel setup. You can do this by setting
turn_detection=None
when you initialize the model. Here's a little example to guide you:
Copy code
from livekit.plugins.openai.realtime import RealtimeModel

# Disable turn detection to prevent interruption of background audio
model = RealtimeModel(
    voice="coral",
    turn_detection=None,  # Disables OpenAI's internal turn detection
)

session = AgentSession(llm=model)
If keeping turn detection is important for your conversation flow, another approach is to separate the background audio from the model’s response lifecycle. You could play it on a different audio track or use LiveKit’s audio mixing features to manage this smoothly. Please feel free to reach out if you'd like me to walk you through any part of this or if you have any other questions—I’m here to help! Sources: OpenAI Realtime API plugin guide | LiveKit docs | plugins/openai/src/realtime/realtime_model.ts | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...
c
i tried all the combinations and still happens the same. Sometimes is when the ai calls a funcion, sometimes is when the user speak for the first time
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!