How can I have transcription events sent to everyo...
# ask-ai
s
How can I have transcription events sent to everyone in a room? Right now they're only being sent to the user who was speaking
t
Thanks for reaching out, Mike. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To share transcription events with everyone in a room, the best way is to use text streams on the 'lk.transcription' topic. This approach is really effective and ensures that transcription data is delivered in real-time and stays synchronized for all participants. Here’s a simple way to get this set up: 1. Use the
stream_text()
method on the local participant to send your transcription data. Make sure to set the topic to
'lk.transcription'
and include helpful metadata like
lk.transcribed_track_id
and
lk.segment_id
to keep everything in sync. 2. Other participants can receive these transcriptions by registering a handler for the
'lk.transcription'
topic using
registerTextStreamHandler()
. Here’s an example of how you might send a transcription:
Copy code
const writer = await room.localParticipant.stream_text({
  topic: 'lk.transcription',
  attributes: {
    'lk.transcribed_track_id': trackSid,
    'lk.segment_id': 'segment-123',
    'lk.transcription.final': 'false'
  }
});

await writer.write("Hello world");
await writer.aclose({ 'lk.transcription.final': 'true' });
And to receive transcriptions, you can do this:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
  let message = '';
  for await (const chunk of reader) {
    message += chunk;
    console.log(`Partial transcription:`, message);
  }
});
This way, everyone in the room will get the transcription events smoothly. If you have any questions or want to dive deeper into this, just let me know—I’m here to help! Sources: hooks/useDataStreamTranscriptions.ts | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | packages/core/src/observables/dataChannel.ts
s
Can my agent code send the transcription to everyone, so that the client code doesn't need to send a separate text stream?
t
Absolutely! Your agent code can send transcriptions to everyone in the room without needing the client code to send a separate text stream. This handy feature is built right into the LiveKit Agents framework and works seamlessly when you use
AgentSession
with transcription enabled. When the agent processes speech-to-text (STT), the transcriptions are automatically shared with all participants through the
'lk.transcription'
text stream topic. This covers both what users say and the agent’s responses, and they’re nicely synced with the audio playback by default. If you’d like, you can also tweak this behavior using `RoomOutputOptions`: • Turn off transcription forwarding:
transcription_enabled: false
• Turn off sync with audio:
sync_transcription: false
Feel free to reach out if you want a hand setting this up or if you have any other questions—I’m here to help! Sources: Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | agents/src/voice/room_io/_output.ts | livekit-agents/livekit/agents/voice/room_io/_output.py