numerous-shampoo-46454
09/12/2025, 2:59 PMtall-airline-16756
09/12/2025, 2:59 PMtall-airline-16756
09/12/2025, 3:00 PMsession.input.set_audio_enabled(False)
method. This will pause the agent's ability to process any incoming audio until you decide to turn it back on with session.input.set_audio_enabled(True)
.
Here’s a friendly example to guide you through it:
session.input.set_audio_enabled(False) # Disable audio input
try:
# Perform your tool call or operation
result = await wait_for_actual_bill(record_id)
finally:
session.input.set_audio_enabled(True) # Re-enable audio input
This way, you make sure no audio input is handled while your tool is working, and everything smoothly resumes once it’s done. If you have any questions or need further help, feel free to ask!
Sources: Turn detection and interruptions | LiveKit Docs | example/lib/widgets/controls.dart | livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt | Real-time audio and video in the Metaverse | Text and transcriptions | LiveKit Docsnumerous-shampoo-46454
09/12/2025, 3:01 PMtall-airline-16756
09/12/2025, 3:02 PMBackgroundAudioPlayer
class in the LiveKit Python SDK. This is a wonderful way to add some ambient sounds, custom audio, or even those "thinking" sounds to enhance the experience during operations.
Here’s a simple example to help you get started with continuous background music:
from livekit.agents import BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip\n\nbackground_audio = BackgroundAudioPlayer(\n ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8)\n)\nawait background_audio.start(room=ctx.room, agent_session=session)
If you'd like to play a custom audio file during the tool execution, here’s how you can do it:
# Play a custom sound file\nbackground_audio.play("/path/to/my-custom-sound.mp3")
Feel free to stop the playback whenever you want, or loop the audio if that suits your needs. If you have any questions or want a hand with the implementation, I’m here to help!
Sources: External data and RAG | LiveKit Docs | Agent speech and audio | LiveKit Docs | examples/drive-thru/drivethru_agent.pynumerous-shampoo-46454
09/15/2025, 12:34 PMtall-airline-16756
09/15/2025, 12:34 PMfrom livekit.agents import function_tool, BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip
class HelpfulAssistant(Agent):
def __init__(self, instructions: str = "You are a helpful assistant.") -> None:
super().__init__(instructions=instructions)
self.background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8)
)
@function_tool()
async def play_background_music(self):
"""Play background music during the session."""
try:
job_ctx = get_job_context()
await self.background_audio.start(room=job_ctx.room, agent_session=self)
return "Background music started successfully."
except Exception as e:
logger.error(f"Error starting background music: {e}")
return f"Error: {str(e)}"
This function sets up a BackgroundAudioPlayer
with a lovely ambient sound and kicks it off when you call the tool. If you'd like, you can easily swap out BuiltinAudioClip.OFFICE_AMBIENCE
for your very own custom audio file path. Feel free to try it out, and if you have any questions or need help customizing it, I'm here for you!