Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/transcribe-captions.md
1---2name: transcribe-captions3description: Transcribing audio to generate captions in Remotion4metadata:5tags: captions, transcribe, whisper, audio, speech-to-text6---78# Transcribing audio910To transcribe audio to generate captions in Remotion, you can use the [`transcribe()`](https://www.remotion.dev/docs/install-whisper-cpp/transcribe) function from the [`@remotion/install-whisper-cpp`](https://www.remotion.dev/docs/install-whisper-cpp) package.1112## Prerequisites1314First, the @remotion/install-whisper-cpp package needs to be installed.15If it is not installed, use the following command:1617```bash18npx remotion add @remotion/install-whisper-cpp19```2021## Transcribing2223Make a Node.js script to download Whisper.cpp and a model, and transcribe the audio.2425```ts26import path from "path";27import {28downloadWhisperModel,29installWhisperCpp,30transcribe,31toCaptions,32} from "@remotion/install-whisper-cpp";33import fs from "fs";3435const to = path.join(process.cwd(), "whisper.cpp");3637await installWhisperCpp({38to,39version: "1.5.5",40});4142await downloadWhisperModel({43model: "medium.en",44folder: to,45});4647// Convert the audio to a 16KHz wav file first if needed:48// import {execSync} from 'child_process';49// execSync('ffmpeg -i /path/to/audio.mp4 -ar 16000 /path/to/audio.wav -y');5051const whisperCppOutput = await transcribe({52model: "medium.en",53whisperPath: to,54whisperCppVersion: "1.5.5",55inputPath: "/path/to/audio123.wav",56tokenLevelTimestamps: true,57});5859// Optional: Apply our recommended postprocessing60const { captions } = toCaptions({61whisperCppOutput,62});6364// Write it to the public/ folder so it can be fetched from Remotion65fs.writeFileSync("captions123.json", JSON.stringify(captions, null, 2));66```6768Transcribe each clip individually and create multiple JSON files.6970See [Displaying captions](display-captions.md) for how to display the captions in Remotion.71