loud-postman-20421
09/19/2025, 10:49 AMtall-airline-16756
09/19/2025, 10:49 AMtall-airline-16756
09/19/2025, 10:50 AMcreatedAt timestamp in the UserInputTranscribedEvent is meant to capture the exact moment when the transcription is created. Sometimes, there might be a little delay because of speech-to-text (STT) processing time, which is totally normal. To help you get the most accurate timing:
• Try using the createdAt field from events where isFinal: true, as this reflects the complete utterance timing more reliably.
• Make sure your system clocks are synced up with NTP to prevent any clock drift issues.
• Keep an eye on STT latency metrics to get a sense of any delays between the speech and the transcription.
If you're running tests in a simulation environment, a tolerance-based comparison function can be really handy to account for those expected delays. Please feel free to reach out if you'd like me to walk you through this or if you have any other questions—I’m here to help!
Sources: Events and error handling | LiveKit Docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Cartesia TTS integration guide | LiveKit Docs | ElevenLabs TTS integration guide | LiveKit Docs | agents/src/voice/room_io/room_io.tsloud-postman-20421
09/19/2025, 10:51 AMtall-airline-16756
09/19/2025, 10:52 AMmetrics_collected event from the STT component. This event gives you a STTMetrics object with some really useful properties:
• `duration`: This tells you how long the STT model took to create the transcript.
• `audio_duration`: This shows the length of the audio input that was sent to the STT model.
• `streamed`: This indicates whether the transcription was done in streaming mode.
Here’s a friendly example in Python to get you started:
from livekit.agents import metrics
from livekit.plugins import deepgram
stt = deepgram.STT()
@stt.on("metrics_collected")
def on_stt_metrics(metrics: metrics.STTMetrics):
print(f"STT Duration: {metrics.duration} seconds")
print(f"Audio Duration: {metrics.audio_duration} seconds")
print(f"Streamed: {metrics.streamed}")
If you have any questions or need a hand with setting this up, please don’t hesitate to ask—I’m here to help!
Sources: agents/src/metrics/usage_collector.ts | Logs, metrics, and telemetry | LiveKit Docs | Capturing metrics | LiveKit Docs | livekit-agents/livekit/agents/metrics/base.pyloud-postman-20421
09/19/2025, 11:36 AMtall-airline-16756
09/19/2025, 11:36 AMloud-postman-20421
09/19/2025, 11:36 AMtall-airline-16756
09/19/2025, 11:38 AMon_start_of_speech callback in the VAD system. This gives you a neat way to estimate the start time by subtracting the speech_duration from the current time. Here's a quick example:
def on_start_of_speech(self, ev: vad.VADEvent):
start_time = time.time() - ev.speech_duration
print(f"User started speaking at: {start_time}")
• User State Change Events: Another approach is to subscribe to the user_state_changed event. When the state switches to speaking, that timestamp marks the beginning of speech. Here's how you might do it:
@session.on("user_state_changed")
def on_user_state_changed(event):
if event.new_state == "speaking":
print(f"User started speaking at: {time.time()}")
• End of Turn Metrics: Lastly, you can tap into the on_end_of_turn hook to get detailed timing info, like when the user last spoke and the full duration.
If you'd like, I'm here to help you walk through implementing any of these methods—just let me know!
Sources: tests/test_agent_session.py | Text and transcriptions | LiveKit Docs | Voice activity detection (VAD) parameters | LiveKit Docsloud-postman-20421
09/19/2025, 11:56 AMtall-airline-16756
09/19/2025, 11:56 AMuser_state_changed event includes a created_at timestamp (in Python) or createdAt (in TypeScript/JavaScript), which shows the exact moment the state transition happened. This timestamp is really helpful to know exactly when the new_state was entered.
If you’re noticing any delays, it might be a good idea to check that your system clocks are synchronized using NTP to keep everything in sync. Please feel free to reach out if you’d like me to help you with this or if you have any other questions—I’m here for you!
Sources: agents/src/voice/events.ts | livekit-agents/livekit/agents/voice/agent_session.pyloud-postman-20421
09/19/2025, 12:01 PMtall-airline-16756
09/19/2025, 12:01 PMloud-postman-20421
09/19/2025, 12:08 PM