* Convert audio file to 16kHz mono WAV if not already in that format.
(audioPath: string)
| 187 | * Convert audio file to 16kHz mono WAV if not already in that format. |
| 188 | */ |
| 189 | function 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. |
no test coverage detected