I have added self.session.say('hhmmmm') inside `o...
# ask-ai
f
I have added self.session.say('hhmmmm') inside
on_user_turn_completed
but total latency for it is still the same as when I use STT + LLM + TTS to generate normal output
t
Thanks for reaching out, Dmitry. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand that reducing latency when using
self.session.say
in the
on_user_turn_completed
callback is important to you. Here are some friendly tips that might help: • Enable Preemptive Generation: This is a great way to get a head start on response generation as soon as the final transcript is ready. It helps reduce latency by overlapping STT, LLM, and TTS processing. You can set this up with
voice_options={"preemptive_generation": True}
. • Minimize Callback Delay: Try to keep the logic inside
on_user_turn_completed
as light as possible. For heavier tasks, consider offloading them using
asyncio.create_task()
to keep things running smoothly. • Use Pre-Synthesized Audio: If possible, passing pre-generated audio frames to
session.say()
can help you skip the real-time TTS synthesis and save time. • Monitor Metrics: Keep an eye on built-in metrics like
on_user_turn_completed_delay
and `ttfb`—they’re super helpful for spotting where any slowdowns might be happening. Please feel free to reach out if you’d like me to walk you through any of these steps in more detail or if there’s anything else I can assist you with. I’m here to help! Sources: Agent speech and audio | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Agent speech and audio | LiveKit docs | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | livekit-agents/livekit/agents/voice/agent_session.py
f
how do I track on_user_turn_completed_delay
t
I'd be happy to help you track
on_user_turn_completed_delay
using the
EOUMetrics
system! This metric is emitted when turn detection is enabled. Here’s a simple way to get started: • Enable Turn Detection: First, make sure your session is using
turn_detection
, like VAD or a turn detector plugin. • Subscribe to Metrics Events: Next, listen for the
metrics_collected
event to capture and log the delay. Here’s an example to guide you:
Copy code
def __init__(self):
    self.session.on("metrics_collected", self.on_metrics_collected)

async def on_metrics_collected(self, event):
    if event.metrics.type == "eou_metrics":
        delay = event.metrics.on_user_turn_completed_delay
        print(f"Callback delay: {delay} seconds")
• Monitor Metrics: Keep in mind, this delay includes the time your
on_user_turn_completed
logic takes to run, so try to keep it lightweight to reduce latency. If you have any questions or want me to walk you through the implementation, just let me know—I’m here to help! Sources: Logs, metrics, and telemetry | LiveKit Docs | Logs, metrics, and telemetry | LiveKit docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Pipeline nodes and hooks | LiveKit docs
f
how does EOU metric calculated? what does it consist of? I am using VAD
t
Let me walk you through how the EOU (End-of-Utterance) metric is calculated when VAD is enabled—it’s a bit detailed, but I’m here to help you understand every step! • End of Utterance Delay: This is the time from when VAD detects the end of speech (that moment of sustained silence) to when your turn is officially marked as complete. It also includes any endpointing delays you might have set up. • Transcription Delay: This measures the time between detecting the end of speech and when the final transcript is ready for you. So, VAD spots the
END_OF_SPEECH
event once silence goes beyond the set threshold (like
min_silence_duration
). After that, the system adds: • Min Endpointing Delay: A brief pause (usually 0.5 seconds) for cases where the turn completion is very confident. • Max Endpointing Delay: A longer pause (around 6.0 seconds by default) for less certain situations, often influenced by the language context. All these delays, plus timestamps such as
lastSpeakingTime
and
lastFinalTranscriptTime
, come together to calculate your EOU metrics. If you’d like, I’d be happy to guide you through setting up VAD parameters or clarifying any of these delays—just let me know! Sources: agents/src/voice/audio_recognition.ts | Logs, metrics, and telemetry | LiveKit docs | Logs, metrics, and telemetry | LiveKit Docs | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | How does end-of-utterance detection work in conversations?