when my agent uses client side tools, they get tri...
# ask-ai
c
when my agent uses client side tools, they get triggered by the client before the TTS that came before has been fully delivered, is there a way for the client to wait for the TTS that came before to be fully delivered before executing the tool call?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m glad you asked about making sure client-side tools wait for the TTS to finish before moving forward! You can achieve this smoothly by using the
SpeechHandle
object, which you get from methods like
say()
or
generate_reply()
. This handy object helps you coordinate so that the TTS audio finishes playing before any tools start executing. Here’s a simple way to do it: • First, capture the
SpeechHandle
when you start the TTS. • Then, use
await handle.wait_for_playout()
or
await speech_handle.wait_if_not_interrupted([audio_output.wait_for_playout()])
to pause your process until the TTS audio has fully played. This approach ensures your client-side tools kick in only after the TTS has wrapped up, keeping everything in the right order and avoiding any interruptions. If you need any more help with this, feel free to ask—I’m here to support you! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | agents/src/voice/agent_activity.ts | Agent speech and audio | LiveKit Docs