Skip to content

🎥 Make videos programmatically with React

rename onUpdate to onTranscribedChunks

Igor Samokhovetsdf2bb54624af
diff --git a/packages/example/src/WhisperWasm/index.tsx b/packages/example/src/WhisperWasm/index.tsx
index 3dfae5ad78..f5d6737879 100644
--- a/packages/example/src/WhisperWasm/index.tsx
+++ b/packages/example/src/WhisperWasm/index.tsx
@@ -8,6 +8,10 @@ import {WhisperModel} from '@remotion/whisper-wasm/src/constants';
import {useCallback, useEffect, useState} from 'react';
import {staticFile} from 'remotion';
+const audioFileUrl = staticFile('16khz.wav');
+
+const model = 'base';
+
export const WhisperWasm = () => {
const [loadedModels, setLoadedModels] = useState<WhisperModel[]>([]);
@@ -18,7 +22,7 @@ export const WhisperWasm = () => {
const onClick = useCallback(async () => {
const {alreadyDownloaded} = await downloadWhisperModel({
- model: 'tiny.en',
+ model,
onProgress: (progress) => {
console.log(progress);
},
@@ -29,14 +33,17 @@ export const WhisperWasm = () => {
}, [fetchModels]);
const onClickTranscribe = useCallback(async () => {
- const file = await fetch(staticFile('16khz.wav'));
+ const file = await fetch(audioFileUrl);
const blob = await file.blob();
const transcription = await transcribe({
- model: 'tiny.en',
+ model,
file: blob,
onProgress(p) {
console.log({p});
},
+ onTranscribedChunks(transcription) {
+ console.log({transcription});
+ },
});
console.log({transcription});
}, []);
@@ -46,9 +53,23 @@ export const WhisperWasm = () => {
}, [fetchModels]);
return (
- <div>
- <button onClick={onClick}>Download</button>
- <button onClick={onClickTranscribe}>Transcribe</button>
+ <div className="flex flex-col gap-2">
+ <button
+ style={{
+ background: 'white',
+ }}
+ onClick={onClick}
+ >
+ Download
+ </button>
+ <button
+ style={{
+ background: 'white',
+ }}
+ onClick={onClickTranscribe}
+ >
+ Transcribe
+ </button>
<div>
{loadedModels.map((model) => (
<div key={model}>
diff --git a/packages/whisper-wasm/src/transcribe.ts b/packages/whisper-wasm/src/transcribe.ts
index ca03fff7f7..1ba38b0685 100644
--- a/packages/whisper-wasm/src/transcribe.ts
+++ b/packages/whisper-wasm/src/transcribe.ts
@@ -105,7 +105,9 @@ export type TranscribeParams = {
model: WhisperModel;
language?: WhisperLanguage;
onProgress?: (p: number) => void;
- onUpdate?: (json: TranscriptionItemWithTimestamp[]) => void;
+ onTranscribedChunks?: (
+ transcription: TranscriptionItemWithTimestamp[],
+ ) => void;
threads?: number;
};
@@ -125,7 +127,7 @@ export const transcribe = async ({
language = 'auto',
onProgress,
threads,
- onUpdate,
+ onTranscribedChunks,
}: TranscribeParams): Promise<TranscriptionJson> => {
checkForHeaders();
@@ -180,7 +182,7 @@ export const transcribe = async ({
reject(new Error('Another transcription is already in progress'));
},
onUpdate: (json: TranscriptionJson) => {
- onUpdate?.(json.transcription);
+ onTranscribedChunks?.(json.transcription);
},
});