stocky-sundown-99393
02/26/2026, 7:24 AMtall-airline-16756
02/26/2026, 7:24 AMtall-airline-16756
02/26/2026, 7:25 AMmetrics_collected and eou_metrics_collected events; those events contain the STT and end-of-utterance metrics you need.
If you want a runnable example, please tell me whether you’re using Python or Node and whether you want metrics logged server-side (inside an AgentSession) or forwarded to your own telemetry system. Below is a concise Python example and a quick explanation of the key metrics.
1) Minimal Python example (inside your AgentSession)
from livekit.plugins import sarvam
from livekit.agents import AgentSession
# create session with Sarvam STT
session = AgentSession(
stt=sarvam.STT(model="saaras:v3", language="hi-IN"),
# ... other configuration
)
# STT metrics listener
def on_stt_metrics(metrics):
print(f"STT duration: {metrics.duration:.4f}s")
print(f"Audio duration: {metrics.audio_duration:.4f}s")
print(f"Speech ID: {metrics.speech_id}")
print(f"Error: {metrics.error}")
print(f"Streamed: {metrics.streamed}")
# End-of-utterance metrics listener
def on_eou_metrics(metrics):
print(f"End-of-utterance delay: {metrics.end_of_utterance_delay:.4f}s")
print(f"Transcription delay: {metrics.transcription_delay:.4f}s")
print(f"Speech ID: {metrics.speech_id}")
# Attach listeners (do this during session startup / on_enter)
session.stt.on("metrics_collected", on_stt_metrics)
session.stt.on("eou_metrics_collected", on_eou_metrics)
2) Key metrics you’ll receive
• duration: total processing time for the STT request.
• audio_duration: length of the audio input in seconds.
• end_of_utterance_delay: time from speech end to EOU detection.
• transcription_delay: time from EOU to full transcription.
• speech_id: unique identifier for the speech segment.
• error: any error message when transcription fails.
• streamed: boolean indicating whether the response was streamed.
3) Where to place listeners
• Attach these listeners in your agent’s startup flow (for example, inside on_enter()), so they activate when the session begins.
Next steps / quick questions to help me tailor this:
• Do you want sample code in Node instead of Python?
• Do you need the metrics sent to a logging/monitoring system (e.g., Prometheus, Datadog) or simply printed/logged server-side?
• Which specific metric(s) are most important for your use case (latency, EOU timings, audio length, errors, etc.)?
Tell me your answers and I’ll give the exact sample code/config for your environment.
Sources: Sarvam STT plugin guide | LiveKit Documentation | STT Metrics | LiveKit Documentation | Speech-to-text (STT) models overview | LiveKit Documentationstocky-sundown-99393
02/26/2026, 7:29 AMtall-airline-16756
02/26/2026, 7:29 AMsession.on("metrics_collected") and need accurate STT timings. Let’s narrow this down and get you precise numbers.
Quick checklist (please confirm these so I can give exact code):
• Are you using Python or Node?
• Which LiveKit Agents / livekit-plugins-sarvam version are you running?
• Are you attaching the listener on the top-level session (session.on("metrics_collected")) or on the STT component (session.stt.on(...))?
• Are you running the listeners inside the agent’s startup (for example, inside on_enter()), or after the session has already started?
Why you’re likely seeing zeros
• The generic session.on("metrics_collected") receives a broad MetricsCollectedEvent that may not include the detailed STT-specific timing fields (or they may be unpopulated) — this can yield zeros.
• STT providers emit richer, provider-specific events (like metrics_collected and eou_metrics_collected) on the STT component itself. Those events include duration, audio_duration, end_of_utterance_delay, transcription_delay, speech_id, streamed, and error. Listening on the STT component is required to receive accurate values.
What to do to get accurate metrics
1. Attach listeners directly to the STT plugin instead of the top-level session event:
◦ Use session.stt.on("metrics_collected", handler) and session.stt.on("eou_metrics_collected", handler) so you receive STT-specific metric objects.
1. Ensure listeners are registered before streaming begins:
◦ Add the listeners during agent startup (for example, on_enter()), so they’re active for all incoming audio.
1. Confirm the Sarvam STT plugin is configured and enabled:
◦ Make sure you initialized sarvam.STT(...) in your AgentSession and that SARVAM_API_KEY is set.
1. Verify you are reading the right fields from the STT metrics object:
◦ Use metrics.duration, metrics.audio_duration, metrics.speech_id, and for EOU events metrics.end_of_utterance_delay and metrics.transcription_delay.
1. Check for streamed vs non-streamed behavior:
◦ If the STT response is streamed, some timing values may be populated differently. The streamed boolean on the STT metrics helps interpret them.
1. If values are still zero:
◦ Confirm audio is actually being delivered to the STT plugin (log incoming audio timestamps).
◦ Confirm the STT provider returns metrics for your chosen model (saaras:v3 etc.). Some models/providers may not populate all fields.
◦ Ensure there are no exceptions in the STT pipeline that cause early returns — inspect metrics.error.
Minimal Python example (attach to STT component)
# Attach listeners during startup / on_enter
def on_stt_metrics(metrics):
print("STT metrics:", metrics.duration, metrics.audio_duration, metrics.streamed, metrics.error)
def on_eou_metrics(metrics):
print("EOU metrics:", metrics.end_of_utterance_delay, metrics.transcription_delay, metrics.speech_id)
session.stt.on("metrics_collected", on_stt_metrics)
session.stt.on("eou_metrics_collected", on_eou_metrics)
Next steps I can provide once you confirm environment:
• A Node or Python full example placed in the correct lifecycle hook (e.g., on_enter()).
• Targeted debug steps to confirm audio delivery and verify Sarvam is populating metrics.
• A snippet that forwards metrics to your logging/monitoring so you can audit values per request.
Tell me: which language and where you’re currently attaching the listener (session vs session.stt), plus your plugin version — I’ll give the exact code and debugging steps.