how can i acces transcriptionreceived events in re...
# ask-ai
b
how can i acces transcriptionreceived events in react native for a realtime convo with 4o mini
t
Thanks for reaching out, Jamal. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! To access
transcriptionReceived
events in React Native for a real-time conversation, you can listen to the
RoomEvent.TranscriptionReceived
event through the LiveKit SDK. This event provides you with real-time transcription segments from participants, even in larger sessions with up to 40 participants or more. Here’s a friendly example to help you get started:
Copy code
import { useEffect, useState } from "react";
import { TranscriptionSegment, RoomEvent } from "livekit-client";
import { useMaybeRoomContext } from "@livekit/components-react";

export function useTranscriber() {
  const room = useMaybeRoomContext();
  const [transcriptions, setTranscriptions] = useState<{ [id: string]: TranscriptionSegment }>({});

  useEffect(() => {
    if (!room) return;

    const handleTranscriptionReceived = (
      segments: TranscriptionSegment[],
      participant?: Participant,
      publication?: TrackPublication
    ) => {
      setTranscriptions(prev => {
        const newTranscriptions = { ...prev };
        for (const segment of segments) {
          newTranscriptions[segment.id] = segment;
        }
        return newTranscriptions;
      });
    };

    room.on(RoomEvent.TranscriptionReceived, handleTranscriptionReceived);

    return () => {
      room.off(RoomEvent.TranscriptionReceived, handleTranscriptionReceived);
    };
  }, [room]);

  return { transcriptions };
}
Just a quick heads-up: the
TranscriptionReceived
event is deprecated and will be removed in a future version. To keep your app up-to-date and running smoothly, LiveKit suggests using text streams on the
lk.chat
topic instead. If you'd like, I’d be more than happy to guide you through migrating to text streams so your application stays future-proof. Just let me know! Sources: complex-agents/teleprompter/teleprompter-frontend/hooks/use-transcriber.ts | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | hooks/useDataStreamTranscriptions.ts | Transcriptions | LiveKit Docs
b
how can i use lk.chat
t
To use
lk.chat
in LiveKit for real-time messaging and transcription, let me guide you through the steps: Sending Messages You can easily send text messages to the
lk.chat
topic by using the
sendText
method on the local participant:
Copy code
const text = 'Hello, how are you today?';
const info = await room.localParticipant.sendText(text, {
  topic: 'lk.chat',
});
Receiving Transcriptions and Messages To receive transcriptions and messages, you’ll want to register a handler for the
lk.transcription
topic using
registerTextStreamHandler
like this:
Copy code
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}`);
  }
});
Additional Notes • The
RoomEvent.TranscriptionReceived
event is now deprecated, so it’s best to use text streams on the
lk.transcription
topic instead. • You can also combine chat messages and transcription streams into one seamless chronological feed, creating a smooth and unified experience for your users. If you’d like, I’m here to help you with implementing this in your React Native project or to answer any questions you might have! Sources: Text and transcriptions | LiveKit Docs | Docs::Agents | hooks/useChatAndTranscription.ts | complex-agents/nova-sonic/nova-sonic-form-agent/hooks/useChatAndTranscripti...
b
room.registerTextStreamHandler('lk.transcription', handler) is not available in React Native LiveKit it seems
t
It looks like
room.registerTextStreamHandler
might not be available in the version of the React Native LiveKit SDK you're using. Could you please share which SDK version you have? Also, I'd love to understand if you're looking for another way to manage text streams or transcriptions in your React Native project—I'm here to help!
b
"/react-native": "^2.9.1", "/react-native-expo-plugin": "^1.0.1", "/react-native-webrtc": "^137.0.1",
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
b
i have version 2.9.1