when is on_user_turn_completed function invoked ?
# ask-ai
r
when is on_user_turn_completed function invoked ?
t
Thanks for reaching out, Saurabh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — great question. Here’s when and how
on_user_turn_completed
is invoked, and what it receives. What triggers it •
on_user_turn_completed
runs when the user’s turn has ended — i.e., after the system detects the user has stopped speaking but before the agent generates its reply. • Typical turn-end signals are voice activity detection (VAD), an end-of-speech signal from the STT component, or a turn-detector model. Parameters it receives • `turn_ctx`: the chat context up to, but not including, the user’s latest message. • `new_message`: the user’s latest message (the content of the completed turn). What happens next • After
on_user_turn_completed
executes,
new_message
is appended to the chat context and the agent proceeds to process/generate a response. When this node is available • This hook is available only for STT → LLM → TTS pipelines (i.e., pipelines that have the user’s turn in text form). If you want, tell me which pipeline or SDK you’re using and I can show a short example of where to attach this hook in your code. Sources: Pipeline nodes and hooks | LiveKit Documentation | Turns overview | LiveKit Documentation | External data and RAG | LiveKit Documentation
r
to detect speech earlier what events can be listened to ?
t
Thanks — good follow-up. You asked which events you can listen to to detect speech earlier. Below are the events and signals you can use (from earliest to later): • START_OF_SPEECH ◦ Emitted by the STT node as soon as voice activity is detected and a speech segment begins. This is the earliest low-latency signal that someone has started speaking. • user_state_changed (new_state == "speaking") ◦ Emitted when the system’s VAD or turn-detector model marks the user as speaking. Useful when you rely on local VAD or the platform’s turn detection. • Interim transcription / INTERIM_TRANSCRIPT events ◦ Streaming STT models emit partial (interim) transcripts while the user is speaking. These let you start processing content before the final transcript is ready. • user_input_transcribed / final transcription ◦ Emitted once the STT produces a (final) transcription for the user’s utterance. Useful if you need higher accuracy before acting. How to combine them for earlier detection • Use START_OF_SPEECH or
user_state_changed
for the fastest detection to kick off pre-processing (e.g., start an LLM warm-up or show a typing indicator). • Use interim transcripts to refine or begin intent extraction while the user continues speaking. • Final transcription or
user_input_transcribed
should trigger the steady-state response generation. If you tell me which SDK or pipeline you’re using (browser, Node, Python, or the composite pipeline), I can show a short code snippet showing where to hook these events. Sources: Turns overview | LiveKit Documentation | Agent session | LiveKit Documentation | Agent speech and audio | LiveKit Documentation | examples/voice_agents | livekit/livekit_composite | DeepWiki