将音频重新采样为16kHz
要使用 Whisper、Whisper.cpp、@remotion/install-whisper-cpp 和 Whisper.wasm,你需要提供一个 16 位、16KHz 的 WAVE 音频文件。
🌐 For using Whisper, Whisper.cpp, @remotion/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
你可以使用convertMedia()将任何支持的视频和音频格式转换并重采样到16kHz。
🌐 You can use convertMedia() to convert any of the supported video and audio formats and resample it to 16kHz.
💼 重要的 @remotion/webcodecs 许可证免责声明
We consider a team of 4 or more people a "company".
In a future version of
@remotion/webcodecs, this package will also require the purchase of a newly created "WebCodecs Conversion Seat". Get in touch with us if you are planning to use this package.Resample audio to 16kHzimport {convertMedia ,canReencodeAudioTrack } from '@remotion/webcodecs'; constoutput = awaitconvertMedia ({src : 'https://example.com/input.mp4',container : 'wav',onAudioTrack : async ({track }) => { if ( awaitcanReencodeAudioTrack ({audioCodec : 'wav',track , // Ignore this, bitrate is not used for WAV filesbitrate : 128000,sampleRate : 16000, }) ) { return {type : 'reencode',audioCodec : 'wav',bitrate : 128000,sampleRate : 16000, }; } // If this conversion is not supported, return an error return {type : 'fail', }; }, }); constblob = awaitoutput .save (); // returns a `Blob`
在服务器上
🌐 On the server
你可以使用 ffmpeg 将你的音频转换为 16 位、16KHz 的 WAVE 文件。
🌐 You can use ffmpeg to convert your audio to a 16-bit, 16KHz, WAVE file.
ffmpeg -i /path/to/audio.mp4 -ar 16000 /path/to/audio.wav -y如果你不想安装 FFmpeg,你也可以使用 Remotion 提供的 较小的 FFmpeg 可执行文件。
🌐 If you don't want to install FFmpeg, you can also use the smaller FFmpeg binary provided by Remotion.
npx remotion ffmpeg -i input.mp4 -ar 16000 output.wav -y