broad-lamp-30178
09/09/2025, 10:28 PMtall-airline-16756
09/09/2025, 10:28 PMtall-airline-16756
09/09/2025, 10:29 PMlk.transcription
text stream topic. This is the channel where LiveKit Agents share real-time text responses and transcriptions.
Let me walk you through the main steps:
1. Connect to the Room: Make sure you use a token with the right permissions, like room_join
, to connect your client to the LiveKit room.
2. Register a Text Stream Handler: Use the room.register_text_stream_handler()
method to set up a listener for the lk.transcription
topic. This handler will activate whenever a text stream is published on that topic.
3. Process Incoming Text Streams: When you receive text chunks, read them using the TextStreamReader
. You can tell apart user transcriptions from agent responses by checking if the lk.transcribed_track_id
attribute is present.
Here's a quick example in Python to illustrate:
from livekit import rtc
async def on_text_received(reader: rtc.TextStreamReader, participant_info: dict):
async for text in reader:
print(text)
room.register_text_stream_handler(topic="lk.transcription", handler=on_text_received)
If you'd like, I’m here to help with more details or examples tailored to a specific programming language or platform. Just let me know!
Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents | Text and transcriptions | LiveKit Docs