fierce-dog-7777
07/22/2025, 6:38 PMSTTMetricstall-airline-16756
07/22/2025, 6:38 PMtall-airline-16756
07/22/2025, 6:39 PMfrom livekit.agents.metrics import STTMetrics
# Create your STT instance
stt = deepgram.STT() # or another provider
def stt_metrics_wrapper(metrics: STTMetrics):
asyncio.create_task(handle_stt_metrics(metrics))
stt.on("metrics_collected", stt_metrics_wrapper)
async def handle_stt_metrics(metrics: STTMetrics):
print(f"STT Duration: {metrics.duration}")
print(f"Audio Duration: {metrics.audio_duration}")
print(f"Streamed: {metrics.streamed}")
• JavaScript Example:
stt.on(SpeechEventType.METRICS_COLLECTED, (metrics) => {
console.log('STT Metrics:', {
requestId: metrics.requestId,
duration: metrics.duration,
audioDuration: metrics.audioDuration,
streamed: metrics.streamed,
timestamp: metrics.timestamp
});
});
STTMetrics properties include:
• `audioDuration`: Duration of audio input (seconds)
• `duration`: Time to create transcript (0 for streaming)
• `streamed`: Boolean for streaming mode
• `requestId`: Unique request identifier
• `timestamp`: When metrics were recorded
• `label`: STT provider identifier
• `error`: Any error (optional)
Metrics are emitted after each recognize() call for non-streaming STT, or on RECOGNITION_USAGE events for streaming STT.
Listen for the metrics_collected event to capture and process STTMetrics in your application.
Sources: livekit-agents/livekit/agents/metrics/base.py | metrics/send-metrics-to-3p/send_metrics_to_3p.py | agents/src/metrics/base.ts | STTMetrics | LiveKit Agents