MCPcopy
hub / github.com/mli/autocut / load_audio

Function load_audio

autocut/utils.py:11–21  ·  view source on GitHub ↗
(file: str, sr: int = 16000)

Source from the content-addressed store, hash-verified

9
10
11def 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
24def is_video(filename):

Callers

nothing calls this directly

Calls 1

runMethod · 0.45

Tested by

no test coverage detected