fierce-jordan-44682
09/27/2025, 5:27 AMtall-airline-16756
09/27/2025, 5:27 AMtall-airline-16756
09/27/2025, 5:28 AMfierce-jordan-44682
09/27/2025, 5:29 AMtall-airline-16756
09/27/2025, 5:29 AMmetrics_collected event on the AgentSession. Here's a friendly example in Python to help you get started:
from livekit.agents import AgentSession, MetricsCollectedEvent
from livekit.agents.metrics import STTMetrics
session = AgentSession()
@session.on("metrics_collected")
def on_metrics_collected(ev: MetricsCollectedEvent):
if isinstance(ev.metrics, STTMetrics):
print("STT Metrics:", ev.metrics)
# streamed=True indicates streaming mode
# audio_duration: duration of audio processed
# duration: 0.0 for streaming
This way, you’ll be able to capture and log the STT metrics, including audio_duration. If you have any questions or need a hand with anything else, just let me know—I’m here to help! Sources: Docs::Agents | Logs, metrics, and telemetry | LiveKit Docs | Docs::Agentsfierce-jordan-44682
09/27/2025, 5:32 AMtall-airline-16756
09/27/2025, 5:33 AMmetrics_collected event. Without this subscription, the metrics won’t be captured. Here’s a quick example to guide you: @session.on("metrics_collected")
def on_metrics_collected(ev):
print(ev.metrics)
• STT Initialization: It’s important to double-check that the STT component is properly initialized and integrated into your session. For instance, confirm that your STT provider (like Google) is set up with valid credentials.
• Streaming Mode: If you’re using streaming STT, keep in mind that metrics are linked to RECOGNITION_USAGE events. If these events aren’t firing, the metrics won’t be logged. So, ensure your STT provider is emitting these events regularly.
• Realtime API Limitation: When using Realtime APIs, STT metrics might not be visible because they’re handled internally.
• Error Handling: Also, check if there are any errors during recognition that might be stopping metrics from being emitted. Things like connection issues or retries could be blocking metric generation.
To help you move forward, please verify your subscription to the metrics_collected event and confirm that your STT provider is emitting the RECOGNITION_USAGE events. If you’d like, I’m here to assist with specific configurations or walk you through debugging steps—just let me know! Sources: Logs, metrics, and telemetry | LiveKit Docs | Docs::Agents | Capturing metrics | LiveKit Docs | livekit-agents/livekit/agents/metrics/base.pyfierce-jordan-44682
09/27/2025, 5:34 AMtall-airline-16756
09/27/2025, 5:36 AMRECOGNITION_USAGE events is thoughtfully managed by the STT provider's plugin during streaming transcription. To help you make sure these events are coming through smoothly:
• Use Streaming Transcription: It’s important to use the stream() method for transcription because the recognize() method (which processes batches) doesn’t emit these events.
• Provider Support: Double-check that your STT provider supports RECOGNITION_USAGE events. Providers like Deepgram, AssemblyAI, and Gladia are great examples that emit these events during streaming.
• Event Subscription: Be sure to subscribe to the metrics_collected event and handle the RECOGNITION_USAGE event type within your application logic.
For instance, with the Deepgram plugin, RECOGNITION_USAGE events are sent out every 5 seconds by default, based on internal tracking of audio duration. If you’re using Google STT, it’s a good idea to verify that your credentials and model configurations are set up correctly, since any misconfiguration might stop these events from being emitted properly. If you’d like, I’m here to help you check your STT provider’s setup or troubleshoot any issues you’re facing. Just let me know! Sources: plugins/deepgram/src/stt.ts | main.py | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/stt.p...fierce-jordan-44682
09/27/2025, 5:41 AMmetrics_collected event and handle the RECOGNITION_USAGE event type within your application logic
According to the documentation, isnt the code just like this to handle all events?
usage_collector = metrics.UsageCollector()
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
usage_collector.collect(ev.metrics)
summary = usage_collector.get_summary()
Where i collect the metrics??tall-airline-16756
09/27/2025, 5:42 AMmetrics.UsageCollector actually takes care of RECOGNITION_USAGE events indirectly, and I’d love to walk you through how it all works:
• Event Conversion: When the STT provider emits a RECOGNITION_USAGE event, LiveKit’s system steps in to convert it into an STTMetrics event. This event includes details like audio_duration and other important data.
• UsageCollector Integration: The UsageCollector is set up to listen for STTMetrics events rather than RECOGNITION_USAGE directly. Once it receives an STTMetrics event, it adds the audio_duration into its internal summary.
Your code snippet looks spot on for collecting metrics! If you’re still seeing stt_audio_duration as 0, it might mean that RECOGNITION_USAGE events aren’t being emitted or converted into STTMetrics as expected. This could happen because:
• The STT provider might not be emitting RECOGNITION_USAGE events—sometimes this is due to configuration or session-related issues.
• There could be errors in the STT plugin that are preventing the conversion to STTMetrics.
To help you move forward, I’d suggest double-checking that the STT provider is properly configured and is indeed emitting those RECOGNITION_USAGE events. Please feel free to reach out if you want me to help you verify this or if you need any further troubleshooting support—I’m here to help! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | agents/src/inference/stt.ts | Docs::Agents