how do I get the user's STT on the client side usi...
# ask-ai
n
how do I get the user's STT on the client side using livekit node rtc sdk
t
Thanks for reaching out, rohit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to get a user's STT (speech-to-text) on the client side using the LiveKit Node RTC SDK — here's how to do that. 1. Register a text stream handler for the
lk.transcription
topic:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participantIdentity) => {
  const message = await reader.readAll();
  const attrs = reader.info.attributes || {};

  const isFinal = attrs['lk.transcription_final'] === 'true';
  const transcribedTrackId = attrs['lk.transcribed_track_id'];
  const segmentId = attrs['lk.segment_id'];

  if (transcribedTrackId) {
    console.log(`Transcription from ${participantIdentity} [final=${isFinal}, segment=${segmentId}]:`, message);
  } else {
    console.log(`Text message from ${participantIdentity}:`, message);
  }
});
1. Key attributes to check: •
lk.transcribed_track_id
— identifies that the message is a transcription and which track it came from. •
lk.transcription_final
— "true" for final segments, absent/false for interim updates. •
lk.segment_id
— identifies the transcription segment. 1. Notes: • LiveKit Agents publish transcriptions to
lk.transcription
. • Interim vs final updates may be sent; use
lk.transcription_final
to distinguish. Would you like a variant that stores transcriptions per participant or emits real-time UI updates for interim text? Sources: Text and transcriptions | LiveKit docs
n
what about for the client side livekit js sdk
t
You're asking how to get a user's STT on the client side using the LiveKit JavaScript SDK — here's how. 1. Register a text stream handler for the
lk.transcription
topic:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participant) => {
  try {
    const message = await reader.readAll();
    const attrs = reader.info.attributes || {};

    const isFinal = attrs['lk.transcription_final'] === 'true';
    const transcribedTrackId = attrs['lk.transcribed_track_id'];
    const segmentId = attrs['lk.segment_id'];

    if (transcribedTrackId) {
      console.log(`Transcription from ${participant.identity} [final=${isFinal}, segment=${segmentId}]:`, message);
    } else {
      console.log(`Text message from ${participant.identity}:`, message);
    }
  } catch (err) {
    console.error('Error reading text stream:', err);
  }
});
1. Important attributes to check: •
lk.transcribed_track_id
— indicates this message is a transcription and which audio track it came from. •
lk.transcription_final
—
"true"
for final segments; absent/false for interim updates. •
lk.segment_id
— groups interim and final messages for the same spoken segment. 1. UX tips: • Show interim text while
lk.transcription_final
is not true, then replace with the final text when final arrives to avoid duplicates. • For React apps, consider
useTranscriptions
from
@livekit/components-react
to simplify integration. Would you like an example that accumulates transcriptions per participant or a React-specific snippet? Sources: Text and transcriptions | LiveKit docs