the usage summary is giving the TTS character coun...
# ask-ai
l
the usage summary is giving the TTS character count = 0 for all conversations. code:
Copy code
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    usage_collector.collect(ev.metrics)

async def log_usage():
    summary = usage_collector.get_summary()
    logger.info(f"Usage: {summary}")
    room_name = assistant.config.room_name
    )
ctx.add_shutdown_callback(log_usage)
output:
Usage: {"llm_prompt_tokens": 8501, "llm_prompt_cached_tokens": 0, "llm_completion_tokens": 291, "tts_characters_count": 0, "stt_audio_duration": 80.04999999999984}
t
Thanks for reaching out, vnandan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The STT character count is not directly tracked by LiveKit's metrics system. The usage summary focuses on audio duration for STT metrics, while character counts are not included in the default implementation. If you need to track character counts for STT, you can implement a custom solution by: • Subscribing to the
SpeechEvent
stream. • Counting the characters in the transcribed text for each
FINAL_TRANSCRIPT
or
INTERIM_TRANSCRIPT
event. • Aggregating these counts separately from the built-in metrics. Let me know if you'd like an example of how to implement this custom tracking. Sources: agents/src/stt/stt.ts | livekit-plugins/livekit-plugins-cartesia/livekit/plugins/cartesia/stt.py | SpeechEventType | LiveKit Agents | UsageSummary | LiveKit Agents
l
Then why does the official docs say it does: Aggregating metrics The
metrics
module also includes a
UsageCollector
helper class for aggregating usage metrics across a session. It tracks metrics such as LLM, TTS, and STT API usage, which can help estimate session cost.
t
Hey there! Just a quick note about the
UsageCollector
in LiveKit—it keeps track of the duration of your STT audio, not the number of characters. So, when the docs mention STT API usage, they’re talking about how long the audio is that’s processed by the STT model, not the length of the transcribed text. For TTS (Text-to-Speech), character counts are tracked, but with STT, it’s all about audio duration. If you want to keep an eye on character counts for STT, you’d need to set up a custom way to count the characters in the transcriptions. Hope that helps! Sources: agents/src/stt/stt.ts | livekit-plugins/livekit-plugins-cartesia/livekit/plugins/cartesia/stt.py | Capturing metrics | LiveKit Docs | TTSMetrics | LiveKit Agents
l
im talking about TTS not STT.
t
Hey there! If you’re seeing the TTS character count as 0 in the usage summary, it usually means either no TTS operations have been done yet, or the
charactersCount
property in the
TTSMetrics
isn’t being set correctly. Here’s what you can check to fix this: • Make sure you’re actually running TTS operations during your session. • Double-check that the
TTSMetrics
object is properly updating the
charactersCount
with the number of characters processed. If you’ve confirmed these and it’s still not working, just give me a shout—I’m here to help! Sources: agents/src/metrics/usage_collector.ts | TTSMetrics | LiveKit Agents
l
im sure im using TTS cause the agent is speaking with a voice not just text.
t
Hey there! If you’re noticing that the TTS character count is stuck at 0, even though you’re using TTS, it might be due to a few reasons: • The input text might not be getting passed correctly to the TTS synthesis or streaming methods. • There could be a hiccup in the metrics collection process, like the
charactersCount
field not updating as it should. • Sometimes, an error during TTS processing can stop the metrics from being sent out. • Or, there might be a bug in the TTS implementation where the character count isn’t being set in the metrics object. Here’s how you can troubleshoot this: 1. Double-check that the input text is properly passed to the TTS methods. 2. Look out for any errors coming from the TTS instance. 3. Take a peek at the metrics collection process using logs or a debugger to spot any issues. 4. Make sure the TTS implementation is actually setting the
charactersCount
field in the metrics object. If you’d like, feel free to share which TTS provider you’re using, a snippet of your code, or any error logs you’ve got. I’m here to help you figure this out!