Skip to content

🎥 Make videos programmatically with React

sample rate

Jonny Burger6b83f034029f
diff --git a/packages/docs/docs/install-whisper-cpp/transcribe.mdx b/packages/docs/docs/install-whisper-cpp/transcribe.mdx
index 959a82ce45..0ec3c5e9ae 100644
--- a/packages/docs/docs/install-whisper-cpp/transcribe.mdx
+++ b/packages/docs/docs/install-whisper-cpp/transcribe.mdx
@@ -36,18 +36,7 @@ for (const token of transcription) {
The path to the file you want extract text from.
-The file has to be a 16KHz wav file. You can extract a 16KHz wav file from a video or audio file for
-example by utilizing FFmpeg with the following command:
-
-```bash
-ffmpeg -i input.mp4 -ar 16000 output.wav -y
-```
-
-If you don't want to install FFmpeg, you can also use the [smaller FFmpeg binary](/docs/cli/ffmpeg) provided by Remotion.
-
-```bash
-npx remotion ffmpeg -i input.mp4 -ar 16000 output.wav -y
-```
+The file has to be a 16-bit, 16KHz, WAVE file. See [Resample audio to 16kHz](/docs/webcodecs/resample-audio-16khz#on-the-server) for more information.
### `whisperPath`
diff --git a/packages/docs/docs/webcodecs/TableOfContents.tsx b/packages/docs/docs/webcodecs/TableOfContents.tsx
index 0db632fb62..514bc24793 100644
--- a/packages/docs/docs/webcodecs/TableOfContents.tsx
+++ b/packages/docs/docs/webcodecs/TableOfContents.tsx
@@ -26,6 +26,10 @@ export const WebCodecsGuide: React.FC = () => {
<strong>Fix a MediaRecorder video</strong>
<div>Fix missing video duration and poor seeking performance</div>
</TOCItem>
+ <TOCItem link="/docs/webcodecs/resample-audio-16khz">
+ <strong>Resample audio to 16kHz</strong>
+ <div>Resample an audio track to 16kHz for use with Whisper</div>
+ </TOCItem>
</Grid>
</div>
);
diff --git a/packages/docs/docs/webcodecs/default-on-audio-track-handler.mdx b/packages/docs/docs/webcodecs/default-on-audio-track-handler.mdx
index f60768a1e3..d4476f3c14 100644
--- a/packages/docs/docs/webcodecs/default-on-audio-track-handler.mdx
+++ b/packages/docs/docs/webcodecs/default-on-audio-track-handler.mdx
@@ -59,6 +59,7 @@ export const defaultOnAudioTrackHandler: ConvertMediaOnAudioTrackHandler = async
audioCodec: defaultAudioCodec,
track,
bitrate,
+ sampleRate: null,
});
if (canReencode) {
diff --git a/packages/docs/docs/webcodecs/resample-audio-16khz.mdx b/packages/docs/docs/webcodecs/resample-audio-16khz.mdx
new file mode 100644
index 0000000000..604deb9f5f
--- /dev/null
+++ b/packages/docs/docs/webcodecs/resample-audio-16khz.mdx
@@ -0,0 +1,65 @@
+---
+id: resample-audio-16khz
+title: Resample audio to 16kHz
+slug: /webcodecs/resample-audio-16khz
+crumb: '@remotion/webcodecs'
+---
+
+For using Whisper, Whisper.cpp, [`@remotion/install-whisper-cpp`](/docs/webcodecs/install-whisper-cpp) and Whisper.wasm, you need to provide a 16-bit, 16KHz, WAVE audio file. This page describes approaches for converting your audio in the browser and on the server.
+
+## In the browser
+
+You can use [`convertMedia()`](/docs/webcodecs/convert-media) to convert any of the [supported video and audio formats](/docs/media-parser/format-support) and resample it to 16kHz.
+
+import {LicenseDisclaimer} from './LicenseDisclaimer';
+
+<details>
+ <summary>💼 Important @remotion/webcodecs License Disclaimer</summary>
+ <LicenseDisclaimer />
+</details>
+
+```tsx twoslash title="Resample audio to 16kHz"
+import {convertMedia, canReencodeAudioTrack} from '@remotion/webcodecs';
+
+const output = await convertMedia({
+ src: 'https://example.com/input.mp4',
+ container: 'wav',
+ onAudioTrack: async ({track}) => {
+ if (
+ await canReencodeAudioTrack({
+ audioCodec: 'wav',
+ track,
+ bitrate: 128000,
+ sampleRate: 16000,
+ })
+ ) {
+ return {
+ type: 'reencode',
+ audioCodec: 'wav',
+ bitrate: 128000,
+ sampleRate: 16000,
+ };
+ }
+
+ return {
+ type: 'fail',
+ };
+ },
+});
+
+const blob = await output.save(); // returns a Blob
+```
+
+## On the server
+
+You can use [`ffmpeg`](https://ffmpeg.org/) to convert your audio to a 16-bit, 16KHz, WAVE file.
+
+```bash
+ffmpeg -i /path/to/audio.mp4 -ar 16000 /path/to/audio.wav -y
+```
+
+If you don't want to install FFmpeg, you can also use the [smaller FFmpeg binary](/docs/cli/ffmpeg) provided by Remotion.
+
+```bash
+npx remotion ffmpeg -i input.mp4 -ar 16000 output.wav -y
+```
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index a9e6f07365..5dec3eb77d 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -1041,6 +1041,7 @@ module.exports = {
'webcodecs/rotate-a-video',
'webcodecs/resize-a-video',
'webcodecs/fix-mediarecorder-video',
+ 'webcodecs/resample-audio-16khz',
'webcodecs/track-transformation',
'webcodecs/pause-resume-abort',
'webcodecs/telemetry',
diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.ts
index 85850a0ba6..6f3c2ae498 100644
--- a/packages/install-whisper-cpp/src/transcribe.ts
+++ b/packages/install-whisper-cpp/src/transcribe.ts
@@ -242,7 +242,7 @@ const transcribeToTemporaryFile = async ({
if (stderr.includes('must be 16 kHz')) {
reject(
new Error(
- 'wav file must be 16 kHz - use this command to make it so: "ffmpeg -i input.wav -ar 16000 output.wav -y"',
+ 'wav file must be 16 kHz - See https://www.remotion.dev/docs/webcodecs/resample-audio-16khz#on-the-server on how to convert your audio to a 16-bit, 16KHz, WAVE file',
),
);
}