I'd like to get the start and end times of each ut...
# ask-ai
f
I'd like to get the start and end times of each utterance an agent and a user makes. What would be the best way to do that?
t
Thanks for reaching out, Abdullah. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! To better assist you, could you please let me know if you're trying to extract the start and end times of utterances from recorded sessions, live sessions, or maybe another specific situation? Also, are you working with any particular LiveKit features or APIs for this? I’m here to help you every step of the way!
f
from a live session
t
I'm happy to help you get the start and end times of each utterance during a live session! Here are some friendly pointers to guide you through: For Agent Utterances (AI Speech): • Make sure to enable
use_tts_aligned_transcript=True
in your
AgentSession
configuration. • Then, implement the
transcription_node
method in your agent class to handle
TimedString
objects, which include helpful
start_time
and
end_time
fields.
Copy code
async def transcription_node(
    self, text: AsyncIterable[str | TimedString], model_settings: ModelSettings
) -> AsyncGenerator[str | TimedString, None]:
    async for chunk in text:
        if isinstance(chunk, TimedString):
            <http://logger.info|logger.info>(f"TimedString: '{chunk}' ({chunk.start_time} - {chunk.end_time})")
        yield chunk
Just a quick note: this feature is experimental and currently available only in Python. For User Utterances: • You can tap into the
user_input_transcribed
event to get transcription data with timing info, provided your STT provider supports it (like the Gladia STT plugin). • Also, telemetry attributes such as
lk.start_time
and
lk.end_time
are great for tracking speaking spans. Frontend Access: • Try using
useVoiceAssistant()
for agent transcriptions and
useTrackTranscription()
for user transcriptions. • By combining these and sorting them by
firstReceivedTime
, you can beautifully reconstruct the conversation timeline. If you'd like, I'm here to walk you through any part of the implementation or provide more details. Just let me know! Sources: Text and transcriptions | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/stt.py | complex-agents/nutrition-assistant/nutrition-assistant-frontend/hooks/useCo... | Understanding Transcript Timing in Voice Conversations