🎥 Make videos programmatically with React
initial docs
Patric Salvisberg76211b23e612
diff --git a/packages/docs/components/TableOfContents/install-whisper-cpp.tsx b/packages/docs/components/TableOfContents/install-whisper-cpp.tsxindex 1636ea5efe..2bdf75c548 100644--- a/packages/docs/components/TableOfContents/install-whisper-cpp.tsx+++ b/packages/docs/components/TableOfContents/install-whisper-cpp.tsx@@ -14,6 +14,10 @@ export const TableOfContents: React.FC = () => {<strong>downloadWhisperModel()</strong><div>Download a Whisper model</div></TOCItem>+ <TOCItem link="/docs/install-whisper-cpp/transcribe">+ <strong>transcribe()</strong>+ <div>Transcribe audio from a media file</div>+ </TOCItem></Grid></div>);diff --git a/packages/docs/docs/install-whisper-cpp/transcribe.mdx b/packages/docs/docs/install-whisper-cpp/transcribe.mdxnew file mode 100644index 0000000000..14b66152f0--- /dev/null+++ b/packages/docs/docs/install-whisper-cpp/transcribe.mdx@@ -0,0 +1,58 @@+---+# image: /generated/articles-docs-install-whisper-cpp-download-whisper-model.png+title: transcribe()+crumb: "@remotion/install-whisper-cpp"+---++# downloadWhisperModel()<AvailableFrom v="?"/>++Transcribes a media file by utilizing whisper.cpp.+You should first install Whisper.cpp, for example through [`installWhisperCpp()`](/docs/install-whisper-cpp/install-whisper-cpp).++```tsx twoslash title="transcribe.mjs"+// @module: esnext+// @target: es2022+import path from "path";+import { transcribe } from "@remotion/install-whisper-cpp";++const { transcription } = await transcribe({+ filePath: "pathToYourFile"+ whisperPath: path.join(process.cwd(), "whisper.cpp")+ model: "base.en",+});+```++## Options++### `filePath`++The path to the file you want to transcribe. The accepted file types are ???++### `whisperPath`++The path to your whisper.cpp folder. If you haven't installed whisper, you can use the [installWhisperCpp](docs/install-whisper-cpp/install-whisper-cpp) API to do so.++### `model`++The model you want to use for the transcription.++Possible values: `tiny`, `tiny.en`, `base`, `base.en`, `small`, `small.en`, `medium`, `medium.en`, `large-v1`, `large-v2`, `large-v3`.++Make sure the model you want to use exists in your `whisper.cpp/models` folder. You can ensure a specific model is available locally by utilizing the [downloadWhisperModel()](docs/install-whisper-cpp/download-whisper-model) API++### `modelFolder?`++If you have++## Return value++### `transcription`++A JSON file containing the transcription of the provided media file including timestamps.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/install-whisper-cpp/src/transcribe.ts)+- [`@remotion/install-whisper-cpp`](/docs/install-whisper-cpp)+- [`downloadWhisperModel()`](/docs/install-whisper-cpp/download-whisper-model)+- [`installWhisperCpp()`](/docs/install-whisper-cpp/install-whisper-cpp)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex b66011e4fc..46a80c70cd 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -501,6 +501,7 @@ module.exports = {items: ["install-whisper-cpp/install-whisper-cpp","install-whisper-cpp/download-whisper-model",+ "install-whisper-cpp/transcribe",],},],diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex ad5291f386..b2c8db07b4 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -867,6 +867,13 @@ export const articles = [compId: "articles-docs-install-whisper-cpp-download-whisper-model",crumb: "@remotion/install-whisper-cpp",},+ {+ id: "install-whisper-cpp/transcribe",+ title: "downloadWhisperModel()",+ relativePath: "docs/install-whisper-cpp/transcribe.mdx",+ compId: "articles-docs-install-whisper-cpp-transcribe",+ crumb: "@remotion/install-whisper-cpp",+ },{id: "install-whisper-cpp/index",title: "@remotion/install-whisper-cpp",diff --git a/packages/install-whisper-cpp/src/index.ts b/packages/install-whisper-cpp/src/index.tsindex 24d31d2ac6..4b58be544c 100644--- a/packages/install-whisper-cpp/src/index.ts+++ b/packages/install-whisper-cpp/src/index.ts@@ -4,3 +4,4 @@ export {WhisperModel,} from './download-whisper-model';export {installWhisperCpp} from './install-whisper-cpp';+export {transcribe} from './transcribe';diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.tsindex 98b6360619..8a90343ca0 100644--- a/packages/install-whisper-cpp/src/transcribe.ts+++ b/packages/install-whisper-cpp/src/transcribe.ts@@ -5,12 +5,7 @@ import path from 'node:path';import util from 'node:util';import type {WhisperModel} from './download-whisper-model';-interface TranscribeProps {- whisperPath: string;- model: WhisperModel;- inputPath: string;- modelFolder: string;-}+type transcription = {};const cleanUpTmpFiles = (tmpJSONPath: string, tmpWaveFilePath: string) => {fs.unlink(tmpJSONPath + '.json', (err) => {@@ -82,24 +77,30 @@ const transcribeToTempJSON = async ();};-export const transcribe = async (transcribeProps: TranscribeProps) => {- // Check if whisper exists, throw an error with a good error message if not- const {whisperPath, inputPath, model, modelFolder} = transcribeProps;-+export const transcribe = async ({+ filePath,+ whisperPath,+ model,+ modelFolder,+}: {+ filePath: string;+ whisperPath: string;+ model: WhisperModel;+ modelFolder?: string;+}): Promise<{transcription: transcription}> => {if (!existsSync(whisperPath)) {throw new Error(`Whisper does not exist at ${whisperPath}. Double-check the passed whisperPath. If you havent installed whisper, check out the installWhisperCpp() API at https://www.remotion.dev/docs/install-whisper-cpp/install-whisper-cpp to see how to install whisper programatically.`,);}- // Check if the file exists- if (!existsSync(inputPath)) {- throw new Error(`Input file does not exist at ${inputPath}`);+ if (!existsSync(filePath)) {+ throw new Error(`Input file does not exist at ${filePath}`);}const tmpWaveFilePath = path.join(process.cwd(), 'tmp.wav');const tmpJSONPath = path.join(process.cwd(), 'tmp');- extractToTempAudioFile(inputPath, tmpWaveFilePath);+ extractToTempAudioFile(filePath, tmpWaveFilePath);await transcribeToTempJSON(tmpWaveFilePath,@@ -113,5 +114,5 @@ export const transcribe = async (transcribeProps: TranscribeProps) => {cleanUpTmpFiles(tmpJSONPath, tmpWaveFilePath);- return json;+ return Promise.resolve({transcription: json});};