Skip to content

🎥 Make videos programmatically with React

fixes

Hunain Ahmed11da75dcf62f
diff --git a/packages/whisper-web-example/package.json b/packages/whisper-web-example/package.json
index 0d956da5ba..b149410cf1 100644
--- a/packages/whisper-web-example/package.json
+++ b/packages/whisper-web-example/package.json
@@ -6,7 +6,7 @@
"scripts": {
"dev": "vite --host",
"build": "tsc -b && vite build",
- "lint": "eslint .",
+ "lint": "tsc && eslint .",
"preview": "vite preview"
},
diff --git a/packages/whisper-web-example/src/App.tsx b/packages/whisper-web-example/src/App.tsx
index a145ad561c..f4e2b6b9d4 100644
--- a/packages/whisper-web-example/src/App.tsx
+++ b/packages/whisper-web-example/src/App.tsx
@@ -6,6 +6,7 @@ import DownloadModel from './downloadModel';
import TranscribeAudio from './transcribeAudio';
import MainTitle from './MainTitle';
import Info from './info';
+import type { TranscriptionJson } from '@remotion/whisper-web';
function VBarrier() {
return (
@@ -19,8 +20,8 @@ function VBarrier() {
function App() {
const [transcriptionCompleted, setTranscriptionCompleted] = useState(false);
const [modelDownloading, setModelDownloading] = useState(false);
- const [result, setResult] = useState<any>(null)
- const [file, setFile] = useState<any>(null);
+ const [result, setResult] = useState<TranscriptionJson | null>(null)
+ const [file, setFile] = useState<File | null>(null);
return (
diff --git a/packages/whisper-web-example/src/display.tsx b/packages/whisper-web-example/src/display.tsx
index e2443a8dc1..ab0c6d404f 100644
--- a/packages/whisper-web-example/src/display.tsx
+++ b/packages/whisper-web-example/src/display.tsx
@@ -1,37 +1,44 @@
-import type { TranscriptionJson } from "@remotion/whisper-web";
+import type { TranscriptionItemWithTimestamp, TranscriptionJson } from "@remotion/whisper-web";
import { useEffect, useMemo, useRef, useState } from "react"
-export default function Display({result, audio}: {result: TranscriptionJson, audio: File}){
+export default function Display({result, audio}: {result: TranscriptionJson | null, audio: File | null}){
const audioRef = useRef<HTMLAudioElement | null>(null);
const [transcriptionTextIndex, setTranscriptionTextIndex] = useState(0);
- const audioUrl = useMemo(() => URL.createObjectURL(audio), [audio]);
+ const audioUrl = useMemo(() => audio ? URL.createObjectURL(audio) : undefined, [audio]);
useEffect(() => {
if(!audioRef.current){
return
}
- console.log(result)
audioRef.current.ontimeupdate = () => {
if (!audioRef.current) return;
const activeTime = audioRef.current.currentTime * 1000;
- console.log(activeTime);
- const timedTranscriptionIndex = result.transcription.findIndex((v: any) =>( v.offsets.from <= activeTime && v.offsets.to >= activeTime));
+ let timedTranscriptionIndex = -1;
+ if (result && result.transcription) {
+ timedTranscriptionIndex = result.transcription.findIndex((v: TranscriptionItemWithTimestamp) => (v.offsets.from <= activeTime && v.offsets.to >= activeTime));
+ }
if(timedTranscriptionIndex >= 0){
setTranscriptionTextIndex(timedTranscriptionIndex);
- console.log(timedTranscriptionIndex)
}
}
}, [
- audioRef
- ])
+ audioRef,
+ result
+ ])
+
+ if(!result){
+ return("")
+ }
return (
<div style={{borderRadius: 20, padding:20, paddingRight: 40, paddingLeft: 40, justifyContent: 'center', justifyItems: 'center', gap: 20, alignItems: 'center', gridAutoFlow: 'row', display: 'grid', background: 'rgb(20, 20, 20, 0.8)', backdropFilter: 'blur(20px)', width: 'fit-content'}}>
<h2>Transcription</h2>
<audio controls ref={audioRef} autoPlay src={audioUrl}></audio>
<p >
- <span style={{ opacity: 1, fontWeight: 900}}>{result.transcription.slice(0, transcriptionTextIndex + 1).map(({text}) => text)}</span>
+ <span style={{ opacity: 1, fontWeight: 900}}>
+ {result.transcription.slice(0, transcriptionTextIndex + 1).map(({text}) => text)}
+ </span>
<span style={{opacity: 0.5, fontWeight: 900}}>{
- result.transcription.slice(transcriptionTextIndex+ 1).map(({text}) => text).join(" ")
+ result.transcription.slice(transcriptionTextIndex + 1).map(({text}) => text).join(" ")
}</span>
</p>
</div>)
diff --git a/packages/whisper-web-example/src/downloadModel.tsx b/packages/whisper-web-example/src/downloadModel.tsx
index 3a091e3424..8f70d28e3d 100644
--- a/packages/whisper-web-example/src/downloadModel.tsx
+++ b/packages/whisper-web-example/src/downloadModel.tsx
@@ -2,7 +2,7 @@ import { downloadWhisperModel, type DownloadWhisperModelParams } from "@remotio
import { useState } from "react";
export default function DownloadModel({ setDownloadingModel }: { setDownloadingModel: (downloading: boolean) => void }) {
- let modelOptions: DownloadWhisperModelParams["model"][] = [
+ const modelOptions: DownloadWhisperModelParams["model"][] = [
"tiny.en",
"tiny",
"small",
diff --git a/packages/whisper-web-example/src/selectTranscriptionModel.tsx b/packages/whisper-web-example/src/selectTranscriptionModel.tsx
index ec7dd3df05..5ec6d1eae2 100644
--- a/packages/whisper-web-example/src/selectTranscriptionModel.tsx
+++ b/packages/whisper-web-example/src/selectTranscriptionModel.tsx
@@ -29,6 +29,7 @@ export default function SelectTranscriptionModel({ loadingLoadedModels, modelDow
};
loader()
+ // eslint-disable-next-line
}, [modelDownloading])
return (
<select onChange={(e) => setModelForTranscription(e.target.value as DownloadWhisperModelParams["model"])} disabled={loadingLoadedModels || transcribing}>
diff --git a/packages/whisper-web-example/src/transcribeAudio.tsx b/packages/whisper-web-example/src/transcribeAudio.tsx
index 92ea2405e3..a5c2637a21 100644
--- a/packages/whisper-web-example/src/transcribeAudio.tsx
+++ b/packages/whisper-web-example/src/transcribeAudio.tsx
@@ -12,7 +12,7 @@ export default function TranscribeAudio({
setResult: (result: TranscriptionJson | null) => void,
setTranscriptionCompleted: (completed: boolean) => void,
setFile: (file: File) => void,
- file: File,
+ file: File | null,
modelDownloading: boolean
}) {
const fileref = useRef<HTMLInputElement>(null)
@@ -22,7 +22,6 @@ export default function TranscribeAudio({
const [transcribing, setTranscribing] = useState(false);
const [progress, setProgress] = useState(0);
useEffect(()=>{
- console.log(modelForTranscription)
}, [modelForTranscription])
useEffect(() => {
//sync the file between two input sources