does livekit have a way to play background sounds ...
# ask-ai
i
does livekit have a way to play background sounds during voice bot calls (like ambient office sounds))?
t
Thanks for reaching out, Ed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes, LiveKit provides ways to play background sounds during voice bot calls. Here are two approaches you can consider: • Using a custom AudioHandler class: You can manage background audio playback by implementing a custom AudioHandler class. This approach is useful for scenarios like playing ambient sounds continuously. You can find an example implementation in the AudioHandler Class and integrate it with your agent code. • Playing short audio clips: You can play specific audio files (e.g., music, sound effects, or pre-recorded messages) during certain actions or events in the call. For example, you can trigger a sound effect when retrieving data or performing a specific task. If you need further guidance or examples, feel free to ask! Sources: Building a Guided Meditation Assistant | LiveKit Docs | Handling RAG Delays in Voice Agents | LiveKit Docs
i
If i want to deploy a worker with 10 agents, whats the proper way to do that? are there any examples? this example just shows how to deploy 1 agent in 1 worker right? import logging from dotenv import load_dotenv from livekit import rtc from livekit.agents import ( AutoSubscribe, JobContext, JobProcess, WorkerOptions, cli, llm, metrics, ) from livekit.agents.pipeline import VoicePipelineAgent from livekit.plugins import deepgram, aws, silero, cartesia load_dotenv() logger = logging.getLogger("voice-assistant") def prewarm(proc: JobProcess): proc.userdata["vad"] = silero.VAD.load() async def entrypoint(ctx: JobContext): initial_ctx = llm.ChatContext().append( role="system", text=( "You are a voice assistant created by LiveKit. Your interface with users will be voice. " "You should use short and concise responses, and avoiding usage of unpronouncable punctuation." ), ) logger.info(f"connecting to room {ctx.room.name}") await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY) # wait for the first participant to connect participant = await ctx.wait_for_participant() logger.info(f"starting voice assistant for participant {participant.identity}") dg_model = "nova-3-general" if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP: # use a model optimized for telephony dg_model = "nova-2-phonecall" agent = VoicePipelineAgent( vad=ctx.proc.userdata["vad"], stt=deepgram.STT(model=dg_model), llm=aws.LLM(), tts=cartesia.TTS(), chat_ctx=initial_ctx, ) agent.start(ctx.room, participant) usage_collector = metrics.UsageCollector() *@agent.on*("metrics_collected") def _on_metrics_collected(mtrcs: metrics.AgentMetrics): metrics.log_metrics(mtrcs) usage_collector.collect(mtrcs) async def log_usage(): summary = usage_collector.get_summary() logger.info(f"Usage: ${summary}") ctx.add_shutdown_callback(log_usage) await agent.say("Hello there! How can I help you today?", allow_interruptions=False) if name == "__main__": cli.run_app( WorkerOptions( entrypoint_fnc=entrypoint, prewarm_fnc=prewarm, ), )
t
To deploy a worker with multiple agents in LiveKit, you can follow these guidelines: • LiveKit workers are designed to handle multiple agent instances simultaneously. When a worker is deployed, it registers with the LiveKit server and waits for jobs. Each job corresponds to a room, and the worker instantiates an agent as a participant in that room when a job is accepted. • To scale up, you can deploy multiple instances of your worker. LiveKit will automatically load balance across all available workers in the pool, ensuring efficient resource utilization. The example you provided demonstrates deploying a single agent in a worker. To handle multiple agents, you don't need to modify the worker code significantly, as the worker can already manage multiple agent instances by design. Simply ensure that your deployment environment can support the desired number of concurrent agents. If you need further clarification or examples, feel free to ask! Sources: Deployment and scaling | LiveKit Docs | LiveKit Agents
i
That doesn't really answer my question, can you show me a code example of how to deploy multiple agents in one work?
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.
i
What does the StreamAdapter do and when is it necessary?