(file: Path, sample_rate: int = 16000)
| 22 | |
| 23 | |
| 24 | def preprocess(file: Path, sample_rate: int = 16000) -> NDArray[np.float32]: |
| 25 | if not s.which("ffmpeg"): |
| 26 | p.skip("ffmpeg not found, skipping this test.") |
| 27 | try: |
| 28 | y, _ = ( |
| 29 | ffmpeg.input(file.__fspath__(), threads=0) |
| 30 | .output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sample_rate) |
| 31 | .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True) |
| 32 | ) |
| 33 | except ffmpeg.Error as e: |
| 34 | raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e |
| 35 | |
| 36 | return np.frombuffer(y, np.int16).flatten().astype(np.float32) / 32768.0 |
| 37 | |
| 38 | |
| 39 | def test_invalid_models(): |
no test coverage detected