🎥 Make videos programmatically with React
add vanilla example to whisper-wasm
Igor Samokhovets41e96012bca3
diff --git a/packages/docs/docs/whisper-wasm/index.mdx b/packages/docs/docs/whisper-wasm/index.mdxindex ca30edac3e..0e846eab8d 100644--- a/packages/docs/docs/whisper-wasm/index.mdx+++ b/packages/docs/docs/whisper-wasm/index.mdx@@ -4,6 +4,9 @@ title: '@remotion/whisper-wasm'crumb: 'Transcribe audio in browser'---+import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';+:::warning**Unstable API**: This package is experimental. The API may change in the future.:::@@ -16,6 +19,19 @@ import {TableOfContents} from './whisper-wasm';## Example usage+:::info+This library is UI-agnostic and can be integrated with any frontend framework.+:::++<Tabs defaultValue="react"+values={[+{ label: 'React', value: 'react' },+{ label: 'Vanilla', value: 'html' },+]}+>++<TabItem value='react'>+```tsx twoslashimport {useState} from 'react';import {transcribe, canUseWhisperWasm, resampleTo16Khz, downloadWhisperModel, type WhisperWasmModel} from '@remotion/whisper-wasm';@@ -67,6 +83,60 @@ export default function MyApp() {}```+</TabItem>++<TabItem value="html">++```tsx twoslash+import {transcribe, canUseWhisperWasm, resampleTo16Khz, downloadWhisperModel} from '@remotion/whisper-wasm';++// HTML:+// <input type="file" accept="audio/*" id="audio-input" />+// <p id="status"></p>++const input = document.getElementById('audio-input') as HTMLInputElement;+const status = document.getElementById('status') as HTMLParagraphElement;++input.addEventListener('change', async (e) => {+ const file = input.files?.[0];+ if (!file) return;++ status.textContent = 'Processing...';++ const modelToUse = 'tiny.en';++ const {supported, detailedReason} = await canUseWhisperWasm(modelToUse);+ if (!supported) {+ status.textContent = `Whisper WASM is not supported in this environment: ${detailedReason}`;+ return;+ }++ status.textContent = 'Downloading model...';+ await downloadWhisperModel({+ model: modelToUse,+ onProgress: (p) => (status.textContent = `Downloading model (${Math.round(p * 100)}%)...`),+ });++ status.textContent = 'Resampling audio...';+ const channelWaveform = await resampleTo16Khz({+ file,+ onProgress: (p) => (status.textContent = `Resampling audio (${Math.round(p * 100)}%)...`),+ });++ status.textContent = 'Transcribing...';+ const {transcription} = await transcribe({+ channelWaveform,+ model: modelToUse,+ onProgress: (p) => (status.textContent = `Transcribing (${Math.round(p * 100)}%)...`),+ });+ status.textContent = transcription.map((t) => t.text).join(' ');+});+```++</TabItem>++</Tabs>+## Functions<TableOfContents />