i am building an ui interface to connect the livek...
# ask-ai
g
i am building an ui interface to connect the livekit agent from frontend. i used room token to join the room and now i want to show the live transcription as well
t
Thanks for reaching out, ashutosh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're already joining the room with a room token — next, you can receive the agent's live transcription by listening for the
lk.transcription
text stream the agent publishes. Quick checklist and minimal examples — tell me which frontend SDK/framework you're using (plain livekit-client JS, React, Flutter, etc.) and I'll give tailored code. 1) Ensure the agent is publishing transcriptions • The agent publishes to the
lk.transcription
topic when transcription is enabled on the AgentSession. 2) Register a text-stream handler (JS example) • After connecting the Room, register a handler for `lk.transcription`:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participant) => {
  const text = await reader.readAll();
  const isFinal = reader.info.attributes['lk.transcription_final'] === 'true';
  // update your UI with text; use isFinal to decide styling/commit
});
3) Use React helper (if using @livekit/components-react) •
useTranscriptions()
returns transcription items you can render. 4) Important notes • Interim vs final: check
lk.transcription_final
attribute to distinguish partial vs final results. • Associate with audio:
lk.transcribed_track_id
attribute links the transcript to the audio track/participant. • Token/data permissions: ensure your token allows receiving data/text streams. Tell me which frontend SDK/framework you’re using and whether you want interim transcripts shown live or only final lines — I’ll provide a ready-to-drop code snippet for your stack. Sources: Text and transcriptions | LiveKit docs | Sending text | LiveKit docs | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents
g
i am using react
t
You're using React — here are two concise options to display live transcription: (A) the React hook
useTranscriptions
from @livekit/components-react, and (B) a manual text-stream handler if you need custom behavior. Pick one. A — Quick React hook (recommended) • Install and use
@livekit/components-react
where you already have a connected
Room
.
Copy code
import { useTranscriptions } from '@livekit/components-react';

function TranscriptionPanel() {
  const transcriptions = useTranscriptions(); // array of { sid, text, speaking, participant, ... }

  return (
    <div>
      {transcriptions.map(t => (
        <div key={t.sid}>
          <strong>{t.participant?.identity ?? 'speaker'}</strong>{' '}
          {t.speaking ? <em>{t.text}</em> : <span>{t.text}</span>}
        </div>
      ))}
    </div>
  );
}
• This hook surfaces interim vs final state via
speaking
or fields in each item; render interim in italics, commit on final. B — Manual handler (custom control) • Register a text stream handler for
lk.transcription
after you connect the `Room`:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participant) => {
  const text = await reader.readAll();
  const attrs = reader.info.attributes || {};
  const isFinal = attrs['lk.transcription_final'] === 'true';
  const trackId = attrs['lk.transcribed_track_id'];

  // Update React state: append interim text or replace previous interim for this trackId,
  // then mark final and move to "final" list when isFinal === true.
});
• Pattern suggestion: a. Keep an object map keyed by
trackId
for current interim text. b. On interim (isFinal=false) update the interim map and render it styled. c. On final (isFinal=true) move the text into a finalized array and clear the interim entry. Important notes • The agent publishes transcripts to
lk.transcription
. • Check
lk.transcription_final
to tell interim vs final. •
lk.transcribed_track_id
links transcript to the speaker's audio track. • Ensure your room token grants data/text stream access and that the agent has transcription enabled. Which option do you want exact code for — full component using
useTranscriptions
or a complete manual implementation with state management for interim + final lines?