(file: str, sr: int = 16000)
| 9 | |
| 10 | |
| 11 | def load_audio(file: str, sr: int = 16000) -> np.ndarray: |
| 12 | try: |
| 13 | out, _ = ( |
| 14 | ffmpeg.input(file, threads=0) |
| 15 | .output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sr) |
| 16 | .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True) |
| 17 | ) |
| 18 | except ffmpeg.Error as e: |
| 19 | raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e |
| 20 | |
| 21 | return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0 |
| 22 | |
| 23 | |
| 24 | def is_video(filename): |