happy-fall-6105
10/08/2025, 6:24 AMtall-airline-16756
10/08/2025, 6:25 AMtall-airline-16756
10/08/2025, 6:25 AMBackgroundAudioPlayer class from the Python SDK. Here's a friendly step-by-step guide to make it easy for you:
1. Initialize the BackgroundAudioPlayer: Begin by creating an instance, and you can even add some ambient or thinking sounds to set the mood.
from livekit.agents import BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
2. Start the Player: Once your room and session are ready, you can start the playback during agent initialization.
await background_audio.start(room=ctx.room, agent_session=session)
3. Play Custom Audio Inside a Tool: Whenever you want to play a specific sound on demand, just use .play() inside your function tool.
@function_tool
async def search_web(self, query: str) -> str:
background_audio.play("filepath.ogg")
await asyncio.sleep(5)
return "Search completed successfully."
4. Stop the Player: And when you need to stop all background audio smoothly, simply call:
await background_audio.stop()
Just a quick note: supported audio formats include .ogg, .mp3, and .wav. Make sure the player starts after your room and session are fully ready. If you have any questions or want me to walk you through any part, feel free to ask—I'm here to help!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | complex-agents/drive-thru/session_setup.py | Agent speech and audio | LiveKit Docs | External data and RAG | LiveKit Docspolite-school-16734
10/08/2025, 7:07 AMtall-airline-16756
10/08/2025, 7:07 AMagent_name in its WorkerOptions. Here are the two main ways to do it:
1. Via API: You can use the AgentDispatchService API to explicitly dispatch the agent to a room. Don’t worry if the room doesn’t exist yet—it will be created automatically. There are helpful methods like createDispatch() available in server SDKs such as Node.js and Python.
2. Via Access Token: Another way is to set up the agent dispatch in the roomConfig of a participant’s access token. Once the participant joins the room, the specified agent will be dispatched automatically.
If you’d like, I’d be happy to provide detailed examples or walk you through the implementation step-by-step. Just let me know how I can help!
Sources: Agent dispatch | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | examples/agent_dispatch.py | README.md