boundless-battery-65494
08/19/2025, 6:46 AMtall-airline-16756
08/19/2025, 6:46 AMtall-airline-16756
08/19/2025, 6:46 AMRECOGNITION_USAGE
events. These events are important because they trigger the STTMetrics
in the streaming metrics monitor task. The reason behind this is that ElevenLabs STT handles the whole audio buffer with a non-streaming HTTP request and only sends back a FINAL_TRANSCRIPT
event once it’s done processing.
Because RECOGNITION_USAGE
events aren’t generated during this process, the _metrics_monitor_task
inside the RecognizeStream
class won’t emit STTMetrics
for streaming sessions. But don’t worry — the recognize()
method still sends out metrics for non-streaming requests.
If you’re working with ElevenLabs STT in streaming mode, this is totally expected behavior. Metrics collection works a bit differently between streaming and non-streaming modes. If you want me to walk you through it or if you have any other questions, just let me know — I’m here to help!
Sources: README.md | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p... | Capturing metrics | LiveKit Docsboundless-battery-65494
08/19/2025, 6:52 AMtall-airline-16756
08/19/2025, 6:53 AMTTSEvent.METRICS_COLLECTED
event isn’t showing up for ElevenLabs, could you please check a few things for me?
• Are you using streaming or chunked synthesis with ElevenLabs?
• After pushing text, are you calling flush()
and end_input()
on the ElevenLabs TTS stream?
• Which versions of livekit-agents
and livekit-plugins-elevenlabs
are you working with?
Getting these details will really help us understand whether it’s a usage thing, a setup issue, or maybe even a bug. Thanks so much for checking!
Sources: livekit-agents/livekit/agents/tts/tts.py | agents/src/tts/stream_adapter.ts | TTSEvent | LiveKit Agentsboundless-battery-65494
08/19/2025, 6:58 AMflush()
and end_input()
on the ElevenLabs TTS stream? - NO
• Which versions of livekit-agents
and livekit-plugins-elevenlabs
are you working with? - 0.7.9tall-airline-16756
08/19/2025, 6:58 AMTTSEvent.METRICS_COLLECTED
event is supported in livekit-plugins-elevenlabs
version 0.7.9. But since you’re not using streaming synthesis and haven’t called flush()
or end_input()
, the metrics event might not show up like you’d expect.
To get this working smoothly, make sure the text is properly sent to the ElevenLabs TTS stream, and that you flush and end the stream correctly. These little steps help the metrics collection finish up and trigger the event.
If you want, I’m here to help you walk through these steps—just let me know!
Sources: agents/CHANGELOG.mdboundless-battery-65494
08/19/2025, 6:59 AMtall-airline-16756
08/19/2025, 7:00 AMTTSEvent.METRICS_COLLECTED
with ElevenLabs. I’ve got your back!
Basic Metrics Collection:
import { TTSEvent } from '@livekit/agents';
import { TTS } from '@livekit/plugins-elevenlabs'; // ElevenLabs TTS plugin
// Create ElevenLabs TTS instance
const tts = new TTS();
// Listen for metrics collection events
tts.on(TTSEvent.METRICS_COLLECTED, (metrics) => {
console.log('TTS Metrics:', {
timestamp: metrics.timestamp,
requestId: metrics.requestId,
ttfb: metrics.ttfb, // Time to first byte in milliseconds
duration: metrics.duration, // Total duration in milliseconds
charactersCount: metrics.charactersCount,
audioDuration: metrics.audioDuration, // Audio duration in seconds
cancelled: metrics.cancelled,
label: metrics.label,
streamed: metrics.streamed
});
});
Advanced Metrics Processing:
import { TTSEvent } from '@livekit/agents';
import { TTS } from '@livekit/plugins-elevenlabs';
class TTSMetricsCollector {
constructor() {
this.metrics = [];
}
setupTTS() {
const tts = new TTS();
tts.on(TTSEvent.METRICS_COLLECTED, (metrics) => {
this.collectMetrics(metrics);
});
return tts;
}
collectMetrics(metrics) {
// Store metrics for analysis
this.metrics.push({
...metrics,
timestamp: new Date(metrics.timestamp).toISOString()
});
// Log key performance indicators
console.log(`TTS Performance - TTFB: ${metrics.ttfb}ms, Duration: ${metrics.duration}ms, Characters: ${metrics.charactersCount}`);
// Calculate efficiency ratio
const efficiency = metrics.audioDuration / (metrics.duration / 1000);
console.log(`Audio efficiency: ${efficiency.toFixed(2)}x realtime`);
}
getAverageMetrics() {
if (this.metrics.length === 0) return null;
const totals = this.metrics.reduce((acc, metric) => ({
ttfb: acc.ttfb + metric.ttfb,
duration: acc.duration + metric.duration,
charactersCount: acc.charactersCount + metric.charactersCount,
audioDuration: acc.audioDuration + metric.audioDuration
}), { ttfb: 0, duration: 0, charactersCount: 0, audioDuration: 0 });
const count = this.metrics.length;
return {
avgTTFB: totals.ttfb / count,
avgDuration: totals.duration / count,
avgCharacters: totals.charactersCount / count,
avgAudioDuration: totals.audioDuration / count
};
}
}
// Usage
const collector = new TTSMetricsCollector();
const tts = collector.setupTTS();
If you have any questions or want help integrating these snippets into your app, just let me know—I’m here to help!
Sources: Capturing metrics | LiveKit Docs | agents/src/pipeline/pipeline_agent.tsboundless-battery-65494
08/19/2025, 7:02 AMtall-airline-16756
08/19/2025, 7:02 AMVoicePipelineAgent
with ElevenLabs TTS, you can simply listen for the VPAEvent.METRICS_COLLECTED
event. Here’s a handy Node.js code snippet to get you started:
import { VoicePipelineAgent, VPAEvent } from '@livekit/agents';
import { TTS } from '@livekit/agents-plugin-elevenlabs';
const agent = new VoicePipelineAgent(vad, stt, llm, tts);
// Listen for all metrics including TTS metrics
agent.on(VPAEvent.METRICS_COLLECTED, (metrics) => {
if (metrics.label === 'elevenlabs.TTS') {
console.log('ElevenLabs TTS Metrics:', {
duration: metrics.duration,
charactersCount: metrics.charactersCount,
audioDuration: metrics.audioDuration,
ttfb: metrics.ttfb,
sequenceId: metrics.sequenceId
});
}
});
The VPAEvent.METRICS_COLLECTED
event gives you useful info like duration
, charactersCount
, audioDuration
, and ttfb
. These come straight from the ElevenLabs TTS plugin as it works its magic during synthesis.
If you have any questions or want to dive deeper into this, just let me know—I’m here to help!
Sources: agents/src/tts/tts.ts | PipelineTTSMetrics | LiveKit Agentsboundless-battery-65494
08/19/2025, 7:04 AMtall-airline-16756
08/19/2025, 7:05 AMTTSEvent.METRICS_COLLECTED
isn't triggering for ElevenLabs but works fine with Cartesia, could you share a bit more info?
• Do you see any error logs or messages in the console when using ElevenLabs?
• Is ElevenLabs successfully producing audio output when you try it?
• Which versions of the ElevenLabs and Cartesia plugins are you working with?
• How are you currently listening for the TTSEvent.METRICS_COLLECTED
event in your code?
With these details, we’ll be in a much better spot to pinpoint if it’s something with the setup or maybe a small difference in how it’s implemented. Looking forward to helping you get this sorted!
Sources: livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p... | agents/src/pipeline/pipeline_agent.ts