i am using the React SDK and hook for Transcriptio...
# ask-ai
w
i am using the React SDK and hook for TranscriptionReceived event to calacualte the latency is that correct
t
Thanks for reaching out, Chiranjeevi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring how to calculate transcription latency using the React SDK! To do this with the
TranscriptionReceived
event, you can rely on the
firstReceivedTime
and
startTime
properties from the
TranscriptionSegment
object. By finding the difference between these two, you'll get the end-to-end transcription latency. Here's a simple way to approach it: • Use the
useTranscriber
hook to listen for the
RoomEvent.TranscriptionReceived
event and keep track of transcription segments. • For each final transcription segment, calculate the latency as
firstReceivedTime - startTime
. Just make sure that both
firstReceivedTime
and
startTime
are defined, and use the
.final
flag to avoid calculating too early. If you'd like, I’m here to help with more details or some example code! Sources: hooks/useDataStreamTranscriptions.ts | Text and transcriptions | LiveKit Docs | livekit-android-test/src/test/java/io/livekit/android/room/RoomTranscriptio... | Live Conversations with AI using ChatGPT and WebRTC | Network Quality & Bandwidth Management | livekit/livekit_composite | DeepWi...
w
Can we use this to calculate end to end audio latency
t
I understand that it can be a bit tricky! The
TranscriptionReceived
event and React SDK don’t directly measure the true end-to-end audio latency because they only show the timestamp when the transcription reaches the client, not the entire timeline from audio input to agent response. To get a more accurate picture of end-to-end latency, LiveKit offers backend metrics like
EOUMetrics
(End-of-Utterance Metrics). These include: • Transcription Delay: The time it takes to finish transcribing after the user stops speaking. • End-of-Utterance Delay: The time between when the user finishes speaking and when the agent decides to end their turn. These metrics are automatically generated during the agent’s operation and you can access them through the backend agent SDK. If you'd like, I’m here to help you set up or walk you through using these metrics—just let me know! Sources: Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | agents/src/voice/audio_recognition.ts | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | livekit-agents/livekit/agents/voice/audio_recognition.py | Logs, metrics, and telemetry | LiveKit Docs
w
Can we treat the EOUmetrics for the end to end latency for the users?
t
Thanks for reaching out! EOUMetrics gives you partial latency measurements, like the time from when the user finishes speaking to when the transcription is done or a turn is detected. However, it doesn’t cover the entire end-to-end latency from the user’s input all the way to the agent’s response. If you’re looking for the full picture, including agent processing and response synthesis, I recommend using the
MetricsReport.e2e_latency
field. This metric captures the total latency from user input to the agent’s output. Plus, LiveKit’s OpenTelemetry integration is a great tool to get trace-based observability, helping you analyze the full conversation latency across every component. If you’d like, I’m here to help you set up these metrics or show you how to combine them for a complete monitoring solution—just let me know! Sources: Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Logs, metrics, and telemetry | LiveKit Docs | livekit/livekit_metrics.pb.go
w
Can I get example code for the metric report e2elatency
t
I'd love to help you get comfortable with accessing the
e2e_latency
field from the
MetricsReport
in LiveKit. Here's a simple example in Python that you might find useful: Python Example:
Copy code
from livekit.agents import AgentSession, MetricsCollectedEvent

# Set up event listener for metrics
def on_metrics_collected(event: MetricsCollectedEvent):
    metrics = event.metrics

    # Check if this is a metrics report with e2e_latency
    if hasattr(metrics, 'e2e_latency') and metrics.e2e_latency is not None:
        print(f"End-to-end latency: {metrics.e2e_latency:.4f} seconds")

# Register the event listener
session = AgentSession()
session.on("metrics_collected", on_metrics_collected)
This snippet listens for the
metrics_collected
event and pulls out the
e2e_latency
value, which tells you the total latency from user input all the way to the agent's response. If you'd like, I’m here to provide more examples or help you with another programming language—just let me know! Sources: livekit/livekit_metrics.pb.go | Logs, metrics, and telemetry | LiveKit Docs