Hi! I'm trying to get the start and end times of e...
# agents
f
Hi! I'm trying to get the start and end times of each user and agent utterance, along with the utterance itself, during a session. An example of what I want (as an end result):
Copy code
[
    {
      "start": 0,
      "end": 0,
      "speaker": "Agent",
      "text": "Hello, I'm __'s virtual assistant. How may I assist you today?"
    },
    {
      "start": 12190,
      "end": 12510,
      "speaker": "Caller",
      "text": "Testing."
    },
    {
      "start": 15195,
      "end": 16681,
      "speaker": "Agent",
      "text": "How can I assist you today? "
    }
  ],
I've tried the following: 1. Using events:
conversation_item_added
,
agent_state_changed
,
user_state_changed
a. I'm able to get the start time of an utterance by looking for the agent/user state,
speaking
. I use the
conversation_item_added
event to get the transcription and save the time of receiving that event to be the end time of the utterance. b. For my implementation to work there needs to be a 1-1 relationship between a
agent/user_state_changed
event and the corresponding agent/user
conversation_item_added
event since the information for a single utterance is dependent on both events. Often times, since these events are independent of each other, there will be a state change event that doesn't correspond to a conversation item added event or vice versa. c. An example of a problematic transcript below. There's a user state change without any user conversation item.
Copy code
2025-09-15 09:38:08.649, agent_state_changed-speaking
2025-09-15 09:38:14.070, assistant, Hi, this is _. [Redacted]
2025-09-15 09:38:15.134, user_state_changed-speaking
2025-09-15 09:38:16.375, user, Yes. [Redacted]
2025-09-15 09:38:17.604, agent_state_changed-speaking
2025-09-15 09:38:21.937, user_state_changed-speaking
2025-09-15 09:38:28.888, assistant, [Redacted]
2. Using the user_input_transcribed event a. I tried using this event since user events (state changed events, conversation item added events) seemed to be the most problematic. This gives me a transcription, but only has a
createdAt
field, which doesn't necessarily give me information on the start and end time of the utterance. 3. Using the stt pipeline node and the transcription pipeline node with use_tts_aligned_transcript=True a. The STT pipeline node gives me the full information for each user utterance using the
event.alternatives[0]
SpeechData object. b. The transcription node with
use_tts_aligned_transcript=True
gives me transcription information on the agent with word level timing. The times are relative to the agents turn. I've provided an example below:
Copy code
0.18575963, 0.47600907, Hi, 
0.6037188, 0.7546485, this 
0.7546485, 0.8591383, is
a. Because the timing for the agent transcription is relative to the agents turn and the timing for the user transcription is relative to the start of the call, I was unable to compile both transcriptions without noticing errors. I tried to normalize both values by referencing a
current_time
variable I defined in the
on_enter
pipeline node, but there were still discrepancies with the final transcript -- agent responses appearing before user's speech. What would be the best way to get the full transcription information including the timing of each utterance for an agent and a user?
✅ 1
f
I have a similar issue and I reported here: https://github.com/livekit/agents/issues/3272
🙌 1
g
Just saw your PR around metrics. Hope it gets through soon.