chilly-motorcycle-32290
07/31/2025, 7:36 AMtall-airline-16756
07/31/2025, 7:36 AMtall-airline-16756
07/31/2025, 7:37 AMlk.transcription, you need to register a text stream handler for the transcription topic and access the attributes from the stream info. Below are examples for different SDKs:
JavaScript/TypeScript:
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
const message = await reader.readAll();
// Access transcription metadata
const segmentId = reader.info.attributes['lk.segment_id'];
const transcribedTrackId = reader.info.attributes['lk.transcribed_track_id'];
const isFinal = reader.info.attributes['lk.transcription_final'] === 'true';
if (transcribedTrackId) {
console.log(`Transcription from ${participantInfo.identity}: ${message}`);
console.log(`Segment ID: ${segmentId}`);
console.log(`Track ID: ${transcribedTrackId}`);
console.log(`Is Final: ${isFinal}`);
}
});
Android (Kotlin):
private fun createTranscriptionSegment(streamInfo: TextStreamInfo): TranscriptionSegment {
return TranscriptionSegment(
id = streamInfo.attributes["lk.segment_id"] ?: "",
text = "",
language = "",
final = streamInfo.attributes["lk.transcription.final"]?.toBoolean() ?: false,
firstReceivedTime = Date().time,
lastReceivedTime = Date().time
)
}
Python:
ATTRIBUTE_TRANSCRIPTION_SEGMENT_ID = "lk.segment_id"
ATTRIBUTE_TRANSCRIPTION_TRACK_ID = "lk.transcribed_track_id"
ATTRIBUTE_TRANSCRIPTION_FINAL = "lk.transcription_final"
Available Metadata Attributes:
• lk.segment_id - The segment ID of the transcription
• lk.transcribed_track_id - The associated track ID of the transcription
• lk.transcription_final - Whether the transcription is final
Let me know if you need further clarification or assistance with a specific SDK!
Sources: app/src/main/java/io/livekit/android/example/voiceassistant/datastreams/Rem... | lib/src/core/engine.dart | livekit-agents/livekit/agents/types.py | Text and transcriptions | LiveKit Docschilly-motorcycle-32290
07/31/2025, 7:45 AMtall-airline-16756
07/31/2025, 7:45 AMlk.transcription. The reader object gives you access to metadata through its info.attributes property.
When you register a text stream handler for the lk.transcription topic, the reader object includes an info property that holds attributes and other metadata. Here’s a simple example in JavaScript:
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
const message = await reader.readAll();
if (reader.info.attributes['lk.transcribed_track_id']) {
console.log(`New transcription from ${participantInfo.identity}: ${message}`);
} else {
console.log(`New message from ${participantInfo.identity}: ${message}`);
}
});
Here’s what metadata you can get from the Reader:
• reader.info.attributes - Holds transcription-specific attributes
• reader.info.id - The stream ID
• reader.info.timestamp - When the message was sent
Some common transcription attributes include:
• lk.segment_id - The segment ID of the transcription
• lk.transcribed_track_id - The track ID associated with the transcription
• lk.transcription_final - Indicates if the transcription is final
And if you’re working in Swift, here’s how you might access these attributes:
let segmentID = reader.info.attributes[TranscriptionAttributes.segment.rawValue] ?? reader.info.id
let isFinal = reader.info.attributes[TranscriptionAttributes.final.rawValue] == "true"
This way, you can easily tell different types of transcription messages apart, keep track of their final status, and link them to specific audio tracks or segments. If you have any questions or want to dive deeper, just let me know!
Sources: Text and transcriptions | LiveKit Docs | VoiceAgent/Chat/Receive/TranscriptionStreamReceiver.swift | src/room/attribute-typings.ts