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 }, wherestateis one of theConstants.transcriptionEventsvalues:TRANSCRIPTION_STARTING,TRANSCRIPTION_STARTED,TRANSCRIPTION_STOPPINGorTRANSCRIPTION_STOPPED. - The current state is also available as
transcriptionStatefromuseRoom().
onTranscriptionText
onTranscriptionText()will be triggered whenever transcription text is available.- It receives
{ participantId, participantName, text, timestamp, type }. participantIdandparticipantNameidentify the speaker.timestampis astring.typesays whether the line is partial, which a later line for the same sentence replaces, or the settled sentence. It isnullwhen 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

