mirror of
https://github.com/openai/whisper.git
synced 2025-11-24 06:26:03 +00:00
Merge 76db75f5b51b5d066ce7d010701769ea49b555e4 into c0d2f624c09dc18e709e37c2ad90c039a4eb72a2
This commit is contained in:
commit
c626f6e49c
@ -51,15 +51,16 @@ def load_audio(file: str, sr: int = SAMPLE_RATE):
|
|||||||
"-ac", "1",
|
"-ac", "1",
|
||||||
"-acodec", "pcm_s16le",
|
"-acodec", "pcm_s16le",
|
||||||
"-ar", str(sr),
|
"-ar", str(sr),
|
||||||
|
"-loglevel", "error",
|
||||||
"-"
|
"-"
|
||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
try:
|
result = run(cmd, capture_output=True)
|
||||||
out = run(cmd, capture_output=True, check=True).stdout
|
|
||||||
except CalledProcessError as e:
|
|
||||||
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
|
|
||||||
|
|
||||||
return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
|
if len(result.stderr):
|
||||||
|
raise RuntimeError(f"Failed to load audio: {result.stderr.decode()}")
|
||||||
|
|
||||||
|
return np.frombuffer(result.stdout, np.int16).flatten().astype(np.float32) / 32768.0
|
||||||
|
|
||||||
|
|
||||||
def pad_or_trim(array, length: int = N_SAMPLES, *, axis: int = -1):
|
def pad_or_trim(array, length: int = N_SAMPLES, *, axis: int = -1):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user