MCPcopy Create free account
hub / github.com/aarnphm/whispercpp / preprocess

Function preprocess

tests/export_test.py:24–36  ·  view source on GitHub ↗
(file: Path, sample_rate: int = 16000)

Source from the content-addressed store, hash-verified

22
23
24def 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
39def test_invalid_models():

Callers 4

test_from_pretrainedFunction · 0.85
test_from_paramsFunction · 0.85
test_load_wav_fileFunction · 0.85
test_callbackFunction · 0.85

Calls 2

decodeMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected