average-jordan-45543
11/13/2025, 10:03 AMtall-airline-16756
11/13/2025, 10:04 AMtall-airline-16756
11/13/2025, 10:04 AMcurrent_speech property of the agent session. This handy property gives you the active SpeechHandle if the agent is speaking, or None if there’s no speech happening right now.
From there, you can call the wait_for_playout() method on the current_speech handle to patiently wait until the speech playback is fully done before hanging up. Here’s a simple example to guide you:
@function_tool()
async def end_call(self, ctx: RunContext):
# Check if the agent is currently speaking
current_speech = ctx.session.current_speech
if current_speech:
# Wait for the agent to finish speaking before hanging up
await current_speech.wait_for_playout()
# Proceed to hang up the call
await hangup_call() # or ctx.room.disconnect() depending on your setup
This way, you can avoid disconnecting the call right in the middle of a sentence, which keeps things smooth and professional. Also, if you’d like to keep an eye on when the agent starts and stops speaking, you can subscribe to the agent_started_speaking and agent_stopped_speaking events for real-time updates.
Sources: Agent speech and audio | LiveKit docs | Agent speech and audio | LiveKit docs | Agents telephony integration | LiveKit docs | agent.py | agent/main.py