how to capture end-of-utterance delay in agent?
# ask-ai
b
how to capture end-of-utterance delay in agent?
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to capture the end-of-utterance (EOU) delay in a LiveKit agent, you can use the
PipelineEOUMetrics
interface. It has this handy
endOfUtteranceDelay
property that shows the time between when speech ends (detected by VAD) and when the agent decides to wrap up the user's turn. Here’s a simple way to get to it: 1. Metric Collection: The
endOfUtteranceDelay
pops up as part of the
EOUMetrics
right before the agent plays speech back to the user. Just listen for the
METRICS_COLLECTED
event to grab this info. 2. Example:
Copy code
def eou_metrics_wrapper(metrics: EOUMetrics):
    eou_delay = metrics.end_of_utterance_delay  # Here's the delay
    transcription_delay = metrics.transcription_delay
    # Do whatever you need with these metrics

agent.eou_metrics_event.subscribe(eou_metrics_wrapper)
This way, you can easily capture and use the EOU delay for any analysis or processing you have in mind. If you want to dive deeper, check out the LiveKit documentation on metrics and the Python examples repository. They’ve got some great info to help you along! Sources: Capturing metrics | LiveKit Docs | complex-agents/turn-taking/agent.py
b
Does session have any decorator for this, like we have to capture stt, tts and llm metrics?
t
Hey there! Just a quick heads-up: LiveKit doesn’t have a dedicated session decorator for capturing end-of-utterance (EOU) delay metrics like it does for STT, TTS, and LLM metrics. But no worries—you can still grab those EOU metrics, including
end_of_utterance_delay
and
transcription_delay
, by subscribing to the
eou_metrics_collected
event on the STT component. Here’s a little example to get you started:
Copy code
def eou_metrics_wrapper(metrics: EOUMetrics):
    asyncio.create_task(self.on_eou_metrics_collected(metrics))

stt.on("eou_metrics_collected", eou_metrics_wrapper)
These metrics come from the
EOUMetrics
interface and you can log or analyze them however you like. If you want more details or another example, just give me a shout—I’m here to help! Sources: PipelineEOUMetrics | LiveKit Agents | metrics/metrics_stt.py | livekit-agents/livekit/agents/voice/agent_session.py