Skip to main content
Version: 2.x.x

Video SDK useTranscription Hook - React Native

useTranscription Hook​

useTranscription() takes the transcription callbacks and returns the methods that start and stop realtime transcription for the room.

useTranscription example​

useTranscription react native hook
import { Constants, useTranscription } from "@videosdk.live/react-native-sdk";

function onTranscriptionStateChanged(data) {
const { state } = data;

if (state === Constants.transcriptionEvents.TRANSCRIPTION_STARTING) {
console.log("Realtime Transcription is starting");
} else if (state === Constants.transcriptionEvents.TRANSCRIPTION_STARTED) {
console.log("Realtime Transcription is started");
} else if (state === Constants.transcriptionEvents.TRANSCRIPTION_STOPPING) {
console.log("Realtime Transcription is stopping");
} else if (state === Constants.transcriptionEvents.TRANSCRIPTION_STOPPED) {
console.log("Realtime Transcription is stopped");
}
}

function onTranscriptionText(data) {
let { participantName, text, timestamp } = data;
console.log(`${participantName}: ${text} ${timestamp}`);
}

const { startTranscription, stopTranscription } = useTranscription({
onTranscriptionStateChanged,
onTranscriptionText,
});

Parameters​

onTranscriptionStateChanged​

  • onTranscriptionStateChanged() will be triggered when the state of the realtime transcription changes.
  • It receives { state }, where state is one of the Constants.transcriptionEvents values: TRANSCRIPTION_STARTING, TRANSCRIPTION_STARTED, TRANSCRIPTION_STOPPING or TRANSCRIPTION_STOPPED.
  • The current state is also available as transcriptionState from useRoom().

onTranscriptionText​

  • onTranscriptionText() will be triggered whenever transcription text is available.
  • It receives { participantId, participantName, text, timestamp, type }.
  • participantId and participantName identify the speaker.
  • timestamp is a string.
  • type says whether the line is partial, which a later line for the same sentence replaces, or the settled sentence. It is null when not reported.

Returns​

startTranscription()​

  • startTranscription() is used to start realtime transcription.

Parameters​

config​
  • type : Object

  • required : false

  • This specifies the configurations for realtime transcription. You can specify following properties.

    • webhookUrl: VideoSDK calls this URL when the transcription state changes.
    • summary: Leave it out if you do not want a summary.
      • enabled: Indicates whether realtime transcription summary generation is enabled. Summary will be available after realtime transcription stopped.
      • prompt: provides guidelines or instructions for generating a custom summary based on the realtime transcription content.
    • modelConfig: Object, settings for the transcription model.

stopTranscription()​

  • stopTranscription() is used to stop realtime transcription.

Example​

const { startTranscription, stopTranscription } = useTranscription();

const run = async () => {
await startTranscription({
webhookUrl: "https://www.example.com",
summary: {
enabled: true,
prompt:
"Write summary in sections like Title, Agenda, Speakers, Action Items, Outlines, Notes and Summary",
},
});

await stopTranscription();
};

run();

Got a Question? Ask us on discord