proud-lawyer-39815
10/13/2025, 7:38 PMtall-airline-16756
10/13/2025, 7:38 PMproud-lawyer-39815
10/13/2025, 7:39 PMtall-airline-16756
10/13/2025, 7:39 PMAudioSession.startAudioSession().
• Then, you can route the audio to a wired headset by using AudioSession.selectAudioOutput("headset").
• Also, if you want the system to automatically choose audio outputs for you, you can set a preferred order using preferredOutputList inside AudioConfiguration.
For iOS:
• Good news! Audio usually routes automatically to connected headsets, whether wired or Bluetooth, when your audio session is set up properly.
• If you’d like to give users manual control, you can call AudioSession.showAudioRoutePicker() to bring up the system’s audio route picker.
Just a quick reminder: make sure you call startAudioSession() before trying to change audio outputs on either platform. If you have any questions or need further help, I’m here for you!
Sources: docs/classes/AudioSession.htmlproud-lawyer-39815
10/13/2025, 7:39 PMtall-airline-16756
10/13/2025, 7:39 PMimport asyncio
import os
import json
from livekit import api
from livekit.agent import AgentSession, OutboundCaller
from livekit.job import JobContext
from livekit.stt import deepgram
from livekit.tts import cartesia
from livekit.llm import openai
from livekit.vad import silero
from livekit.turn_detection import EnglishModel
async def entrypoint(ctx: JobContext):
await ctx.connect()
# Parse metadata: phone number and transfer number
dial_info = json.loads(ctx.job.metadata)
phone_number = dial_info["phone_number"]
participant_identity = phone_number
# Initialize STT, TTS, LLM, and VAD
session = AgentSession(
stt=deepgram.STT(),
tts=cartesia.TTS(),
llm=openai.LLM(model="gpt-4o"),
vad=silero.VAD.load(),
turn_detection=EnglishModel(),
)
agent = OutboundCaller(
name="AgentName",
appointment_time="next Tuesday at 3pm",
dial_info=dial_info,
)
# Start session before dialing to avoid missing audio
session_started = asyncio.create_task(session.start(agent=agent, room=ctx.room))
try:
# Initiate outbound call
await ctx.api.sip.create_sip_participant(
api.CreateSIPParticipantRequest(
room_name=ctx.room.name,
sip_trunk_id=os.getenv("SIP_OUTBOUND_TRUNK_ID"),
sip_call_to=phone_number,
participant_identity=participant_identity,
wait_until_answered=True, # Blocks until call is answered
)
)
# Wait for session and participant to join
await session_started
participant = await ctx.wait_for_participant(identity=participant_identity)
agent.set_participant(participant)
print(f"Call connected with {participant_identity}")
except api.TwirpError as e:
print(f"Error creating SIP participant: {e.message}")
ctx.shutdown()
This snippet shows you how to:
• Set up the agent with STT, TTS, LLM, and VAD functionalities.
• Begin a session that processes audio in real-time.
• Place an outbound call using create_sip_participant.
• Listen in on the conversation as soon as the call connects.
Just a quick reminder: please make sure you have your outbound SIP trunk configured and that the SIP_OUTBOUND_TRUNK_ID environment variable is set before you run this code. If you have any questions or need further help, I’m here for you!