refined-airport-68974
12/16/2025, 8:00 PMtall-airline-16756
12/16/2025, 8:01 PMtall-airline-16756
12/16/2025, 8:01 PMrefined-airport-68974
12/16/2025, 8:08 PM- **"transcription_received"**: Called when a transcription is received.
- Arguments: `segments` (list[TranscriptionSegment]), `participant` (Participant), `publication` (TrackPublication)
tell its implementaion in python. how to i process this eventtall-airline-16756
12/16/2025, 8:09 PMtranscription_received signature with segments, participant, publication. That exact event/signature is not documented in the LiveKit Agents docs. Use user_input_transcribed or conversation_item_added (or the lk.transcription text stream) to handle transcriptions in Python.
Below is a concise Python pattern showing how to process transcription events using the documented user_input_transcribed approach. Adjust handlers to match your app's event dispatch system.
1) Example handler and processing flow
# Example types (replace with your SDK imports)
from typing import List
class TranscriptionSegment:
def __init__(self, text: str, start: float = None, end: float = None):
self.text = text
self.start = start
self.end = end
# Handler called when transcription arrives
def on_user_input_transcribed(segments: List[TranscriptionSegment], participant, publication):
# combine segments into one text blob
full_text = " ".join(s.text for s in segments).strip()
if not full_text:
return # nothing to do
# example processing: log, save, or add to conversation
print(f"Transcription from {participant.identity if hasattr(participant,'identity') else participant}: {full_text}")
# Example: emit a conversation item or forward to agent logic
conversation_item = {
"type": "user_message",
"participant_id": getattr(participant, "sid", None),
"text": full_text,
"source": "transcription",
}
handle_conversation_item(conversation_item)
def handle_conversation_item(item):
# implement your app logic: store, run NLU, route to agent, etc.
print("Processing conversation item:", item)
2) If your code really provides `segments, participant, publication`:
• `segments`: treat as list of small portions; join in order, preserving timestamps if needed.
• `participant`: use participant.identity or participant.sid to associate speaker.
• `publication`: can identify which track produced the transcription (useful if multiple mics/tracks).
3) Tips
• If partial segments arrive, buffer until final flag (if your source provides it). If no final indicator, you can treat each callback as incremental and reconcile later.
• Normalize whitespace and punctuation when joining segments.
• Persist transcripts with timestamps when you need search/audit.
If you want, paste a short snippet of the actual event object your code receives (a sample segments structure and participant fields) and I’ll give a tailored handler that plugs into your code.
Sources: Events and error handling | LiveKit docs | Text and transcriptions | LiveKit docsrefined-airport-68974
12/16/2025, 8:19 PMtall-airline-16756
12/16/2025, 8:19 PMlk.transcription text stream. Below is a concise Python example pattern you can adapt to your SDK/event loop. It shows subscribing to the text stream, receiving transcription messages, and printing their content and speaker info.
1) Minimal handler pattern
# Pseudocode / adapt to your LiveKit Python client library
# 1. Connect and join the room (use your client/SDK calls)
client = LiveKitClient(url="<wss://your-livekit>", token="TOKEN")
room = client.join_room("room_name")
# 2. Subscribe to text stream events / messages
def on_text_message(topic: str, message: dict):
# only handle lk.transcription topic
if topic != "lk.transcription":
return
# message shape may vary; common fields:
# - text: the transcribed text
# - participant_id or identity: who spoke
# - segments/timestamps optional
text = message.get("text") or message.get("transcript") or ""
speaker = message.get("participant_id") or message.get("identity") or message.get("speaker")
print(f"[transcription] speaker={speaker} text={text}")
# Register handler with your client's text message dispatcher
room.on_text_message(on_text_message)
2) If the transcription messages include segments:
def on_text_message(topic: str, message: dict):
if topic != "lk.transcription":
return
segments = message.get("segments") or []
if segments:
# join segment texts in order
text = " ".join(s.get("text", "") for s in segments).strip()
else:
text = message.get("text", "")
speaker = message.get("participant_id") or message.get("identity")
print(f"[transcription] speaker={speaker} text={text}")
Notes and tips
• Use the actual event/callback names from your LiveKit Python client (examples above use on_text_message / room.on_text_message as placeholders).
• Inspect one raw message (print the full message dict) to confirm exact field names (some setups use text, others transcript or segments).
• If you need code specifically for your client library, paste the snippet where you handle incoming text-stream events and I’ll adapt the handler to that API.