prehistoric-alligator-43413
10/15/2025, 8:31 PMtall-airline-16756
10/15/2025, 8:31 PMtall-airline-16756
10/15/2025, 8:32 PMuser_input_transcribed: This event gives you real-time transcripts of what the user is saying. Here’s a simple example to show how it works: @session.on("user_input_transcribed")
def on_user_transcript(ev):
print(f"User said: {ev.transcript}")
• conversation_item_added: This one triggers whenever a message—whether from the user or the agent—is added to the chat history, providing finalized transcripts.
• speech_created: This event fires when agent speech is generated, but keep in mind, to get the transcript you’ll want to pull it from the related message or TTS output.
• session.history: This lets you programmatically access the full conversation history, including messages from both users and agents.
Just a heads-up, the events user_speech_committed, agent_speech_committed, and agent_speech_created aren’t valid LiveKit events. If you’d like, I’m happy to walk you through implementing these correctly or answer any other questions you have—just let me know! Sources: Events and error handling | LiveKit Docs | Session recording and transcripts | LiveKit Docs | livekit-agents/livekit/agents/stt/stt.py | pipeline-stt/transcriber/transcriber.py | Understanding Transcript Timing in Voice Conversationsprehistoric-alligator-43413
10/15/2025, 8:40 PMtall-airline-16756
10/15/2025, 8:41 PMsip_trunk_id: This is the ID of the SIP trunk you'll use for your outbound call.
• sip_call_to: The phone number you want to dial.
• room_name: The LiveKit room where the SIP participant will join.
• participant_identity: A unique ID for the SIP participant within the room.
There are also some optional parameters that can be really helpful:
• sip_number: This sets the Caller ID (the From number) that the receiving party will see.
• dtmf: If you need to send DTMF digits after the call connects, this is where you specify them.
• play_dialtone: Choose whether to play a dialtone in the room for other participants.
• headers: You can add custom SIP headers to include in the INVITE message.
• wait_until_answered: This makes the system wait until the call is answered before moving forward.
Make sure these are set up correctly in your session, and please don’t hesitate to reach out if you want me to walk you through any part of this or if you have any other questions. I’m here to help! Sources: livekit-protocol/src/livekit.rs | protobufs/livekit_sip.proto | Preserving Caller ID During SIP Transfers in LiveKit Agents | livekit-protocol/livekit/protocol/sip.pyiprehistoric-alligator-43413
10/15/2025, 10:40 PMtall-airline-16756
10/15/2025, 10:41 PMUsageCollector class. Here's a simple way to do it:
1. *Initialize the UsageCollector:*`usage_collector = UsageCollector()`
2. Collect Metrics: Just use the collect() method to gather token usage from different metrics like LLM or real-time models. For example: # Collect LLM metrics
usage_collector.collect(llm_metrics_instance)
3. Retrieve the Summary: Then, call get_summary() to see the total token usage: summary = usage_collector.get_summary()
print("Prompt Tokens:", summary.llm_prompt_tokens)
print("Completion Tokens:", summary.llm_completion_tokens)
This method helps you keep track of tokens for LLM, TTS, and real-time models easily. If you’d like, I’m here to help with more details or examples—just let me know! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | agents/src/metrics/base.tsprehistoric-alligator-43413
10/15/2025, 10:43 PMtall-airline-16756
10/15/2025, 10:44 PMprehistoric-alligator-43413
10/15/2025, 11:00 PMtall-airline-16756
10/15/2025, 11:02 PMUsageCollector class isn’t found in the root livekit.agents module, but rather in the livekit.agents.metrics submodule. To fix the ImportError, you can update your import statement like this:
from livekit.agents.metrics import UsageCollector
usage_collector = UsageCollector()
If you’re still running into trouble, it’s a good idea to double-check that the livekit-agents package is installed and up to date. You can do that by running:
pip install --upgrade livekit-agents
Please feel free to reach out if you have any more questions or need a hand with anything else! Sources: examples/voice_agents/speedup_output_audio.py | Logs, metrics, and telemetry | LiveKit Docs | chain-of-thought-tts/agent.pyprehistoric-alligator-43413
10/16/2025, 3:31 PMtall-airline-16756
10/16/2025, 3:33 PMid: A unique identifier for each message
• timestamp: The time when the message was created
• edit_timestamp: An optional timestamp for when the message was edited
• message: The actual content of the message
• deleted: A boolean indicating if the message has been deleted
• generated: A boolean showing if the message was AI-generated
To help you accurately parse transcripts, here are some friendly tips: 1. Use conversation_item_added or user_input_transcribed events for processing messages in real-time. 2. For batch processing, you can access session.history once the session has ended. 3. Always check the message field for content, and be prepared to handle different formats like strings, lists, or dictionaries. 4. Use the timestamp field to keep messages in chronological order, and make sure to skip any messages marked as deleted by checking the deleted field. I noticed your current implementation might run into trouble if the content field is a string since strings don’t have a get method. Here’s a little update for your code to handle that smoothly:
if isinstance(content, str):
text = content
elif isinstance(content, list) and len(content) > 0:
first_item = content[0]
if isinstance(first_item, dict):
text = first_item.get('text', '')
elif isinstance(first_item, str):
text = first_item
elif isinstance(content, dict):
text = content.get('text', '')
Please feel free to reach out if you’d like me to clarify anything further or if you need a hand with anything else! I’m here to help. Sources: Session recording and transcripts | LiveKit Docs | lib/livekit/proto/livekit_models_pb.rb | hooks/useDataStreamTranscriptions.ts