gorgeous-hydrogen-44699
12/03/2025, 9:50 AMtall-airline-16756
12/03/2025, 9:50 AMtall-airline-16756
12/03/2025, 9:51 AMlk.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`:
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 Agentsgorgeous-hydrogen-44699
12/03/2025, 9:52 AMtall-airline-16756
12/03/2025, 9:53 AMuseTranscriptions 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.
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`:
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?