future-glass-56154
11/03/2025, 7:44 PMtall-airline-16756
11/03/2025, 7:45 PMtall-airline-16756
11/03/2025, 7:45 PMsession.say()! It’s best to await it when you want to make sure the spoken message finishes before moving on to the next steps. This is really helpful in situations where what happens next depends on the message being fully delivered—like closing a session or switching states. Here’s a simple example:
await self.customer_session.say(
"You are on the line with my supervisor. I'll be hanging up now."
)
await self.customer_session.aclose()
On the flip side, if the message doesn’t need to block what comes next and you want to keep things moving smoothly, you don’t have to await session.say(). For example, inside event handlers like on_user_turn_completed, you can just call session.say() without await so the event loop keeps running without delay:
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
self.session.say("session.say from on_user_turn_completed")
Also, it’s great to know that session.say() returns a SpeechHandle. This lets you keep an eye on playback status or handle interruptions, giving you the flexibility to use it in a non-blocking way while still staying in control.
Sources: livekit-agents/livekit/agents/voice/agent_session.py | Agent speech and audio | LiveKit docs