how to diconnrct call in voice agent without funti...
# ask-ai
c
how to diconnrct call in voice agent without funtion calliong
t
Thanks for reaching out, N. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! If you're looking to disconnect a call in LiveKit Voice Agent without directly using a function call, here are a few friendly options you might consider: • Server-Side Room Deletion: You can use the
delete_room
API to end the entire room, which will disconnect everyone involved. • Client-Side Disconnection: Adding a simple UI button that triggers
Room.disconnect()
lets users gracefully leave the call whenever they want. • Programmatic Agent Session Closure: If you want to disconnect just the agent but keep others connected,
session.aclose()
is a great choice. • Automatic Disconnection: You might also set up the session to close automatically when a participant leaves or the worker shuts down, making things seamless. • Telephony Call Transfer: Another option is to use
transfer_sip_participant
to move the call to another destination, effectively ending the agent’s session. If you could share a bit about your specific scenario—whether it’s web-based, telephony, or part of an automated workflow—I’d be more than happy to help you find the best approach tailored just for you! Sources: Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | complex-agents/drive-thru/frontend/components/livekit/agent-control-bar/age... | components/livekit/agent-control-bar/agent-control-bar.tsx | Agents telephony integration | LiveKit Docs
c
how to check if tts playing is closed before ending the call
t
To make sure the TTS playback has finished before ending your call, here are a couple of helpful methods you can try: • Using the
playback_finished
Event:
You can listen for the
playback_finished
event from the
AudioOutput
. This way, you'll know exactly when the audio playback is complete. Here's an example:
Copy code
@session.output.audio.on("playback_finished")
def _on_playback_finished(ev):
    <http://logger.info|logger.info>("Playback finished")
    # End the call safely here
Using `SpeechHandle`: Another approach is to await the
SpeechHandle
returned by
say()
or
generate_reply()
. This ensures the playback finishes before the call ends. For example:
Copy code
handle = session.generate_reply("Goodbye")
await handle  # Wait for playback to complete
These methods help prevent the call from ending too soon. If you’d like, I’m here to help you implement this or answer any other questions you might have! Sources: How to detect when an agent has finished speaking | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p...