* Extract audio from a video file as 16kHz mono WAV (whisper requirement).
(videoPath: string)
| 142 | * Extract audio from a video file as 16kHz mono WAV (whisper requirement). |
| 143 | */ |
| 144 | function extractAudio(videoPath: string): string { |
| 145 | const ffmpegPath = findFFmpeg(); |
| 146 | if (!ffmpegPath) { |
| 147 | throw new Error( |
| 148 | `ffmpeg is required to extract audio from video. Install: ${getFFmpegInstallHint()}`, |
| 149 | ); |
| 150 | } |
| 151 | const wavPath = tempWavPath(); |
| 152 | execFileSync( |
| 153 | ffmpegPath, |
| 154 | ["-i", videoPath, "-vn", "-ar", "16000", "-ac", "1", "-f", "wav", "-y", wavPath], |
| 155 | { stdio: "ignore", timeout: 120_000 }, |
| 156 | ); |
| 157 | return wavPath; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Check if a WAV file is already 16kHz mono via ffprobe. |
no test coverage detected