brash-fountain-12853
12/04/2025, 7:54 PMtall-airline-16756
12/04/2025, 7:54 PMtall-airline-16756
12/04/2025, 7:54 PMbackground_audio = BackgroundAudioPlayer()
await background_audio.start(room=ctx.room, agent_session=session)
self.background_audio_player = background_audio
1. Play and keep the handle so you can stop or await it:
audio_handle = None
if self.background_audio_player:
audio_handle = self.background_audio_player.play(
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8)
)
# When done or on interruption:
if audio_handle:
audio_handle.stop()
# or: await audio_handle # to wait for completion
1. If the tool runs for a while and you want continuous sound, enable looping:
self.background_audio_player.play(
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
loop=True
)
# stop when the operation completes
1. Handle interruptions (optional but recommended):
• If user speech or other signals can interrupt the tool, stop the PlayHandle in your interruption path.
If you'd like, share:
• how you initialize the agent/session (so I can confirm start() usage), and
• whether you want the sound to loop or stop when the lookup finishes. Sources: Tool definition and use | LiveKit docs | Agent speech and audio | LiveKit docsbrash-fountain-12853
12/04/2025, 8:21 PMtall-airline-16756
12/04/2025, 8:22 PMthinking_sound (agent-managed) or are you calling background_audio_player.play(...) manually inside the tool? 3) How and where do you initialize/start the BackgroundAudioPlayer (session-level vs inside the tool)? — paste the startup snippet if convenient.
Quick guidance you can try right away
• If you’re on Node.js: thinking sounds are not supported. Use manual on-demand playback with background_audio_player.play(...) and loop it during the tool call, then stop the handle when done.
• If you’re on Python: thinking sounds are supported but Gemini Realtime can still mute auxiliary audio during realtime processing. Use manual playback (start looped clip with play(..., loop=True)) at session scope and stop the returned PlayHandle in a finally block of the tool so it keeps playing through the thinking period.
If you share the three items above, I’ll give the exact code changes to keep audio playing during the Gemini Realtime tool call.
Sources: Agent speech and audio | LiveKit docsbrash-fountain-12853
12/04/2025, 8:26 PMtall-airline-16756
12/04/2025, 8:27 PMplay() inside the tool may be getting cut off. The reliable fix in Python is to use BackgroundAudioPlayer’s thinking_sound (session-level) so the player automatically keeps the thinking/typing audio during tool execution. If that isn't viable, start the playback before the tool work and keep the returned PlayHandle alive for the tool duration (or use Gemini text-only + your own TTS).
Two options with concise code you can apply now:
1) Recommended — enable thinking_sound at session init (auto-plays during function_tool)
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
thinking_sound=AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
)
await background_audio.start(room=ctx.room, agent_session=session)
# No need to call play() inside lookup; thinking_sound will play automatically.
2) Fallback — manually play before work and keep the handle alive
@function_tool(...)
async def lookup(self, context: RunContext, query: str) -> str:
audio_handle = None
try:
if self.background_audio_player:
audio_handle = self.background_audio_player.play(
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
loop=True
)
result = await self._perform_search(query) # your work
return result
finally:
if audio_handle:
audio_handle.stop() # or `await audio_handle` to let it finish
If you prefer full control over mixing (no Gemini audio muting), run Gemini in text-only mode and use your own TTS for speech output.
Do you want the exact patch to your current file to switch to thinking_sound, or should I produce the fallback changes integrated into your Tools class?
Sources: Agent speech and audio | LiveKit docs | Gemini Live API plugin | LiveKit docs | Realtime model plugins | LiveKit Docs