MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / prepareAudio

Function prepareAudio

packages/cli/src/whisper/transcribe.ts:189–206  ·  view source on GitHub ↗

* Convert audio file to 16kHz mono WAV if not already in that format.

(audioPath: string)

Source from the content-addressed store, hash-verified

187 * Convert audio file to 16kHz mono WAV if not already in that format.
188 */
189function prepareAudio(audioPath: string): string {
190 if (extname(audioPath).toLowerCase() === ".wav" && isWav16kMono(audioPath)) {
191 return audioPath;
192 }
193
194 // Convert to whisper-compatible WAV
195 const ffmpegPath = findFFmpeg();
196 if (!ffmpegPath) {
197 throw new Error(`ffmpeg is required to prepare audio. Install: ${getFFmpegInstallHint()}`);
198 }
199 const wavPath = tempWavPath();
200 execFileSync(
201 ffmpegPath,
202 ["-i", audioPath, "-ar", "16000", "-ac", "1", "-f", "wav", "-y", wavPath],
203 { stdio: "ignore", timeout: 120_000 },
204 );
205 return wavPath;
206}
207
208/**
209 * Transcribe an audio or video file and save transcript.json to the output directory.

Callers 1

transcribeFunction · 0.85

Calls 4

isWav16kMonoFunction · 0.85
findFFmpegFunction · 0.85
getFFmpegInstallHintFunction · 0.85
tempWavPathFunction · 0.85

Tested by

no test coverage detected