Skip to content

Commit 1f1755f

Browse files
authored
Update audio.py
1 parent 776d28c commit 1f1755f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

infer/lib/audio.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ def load_audio(file, sr):
3434
# This launches a subprocess to decode audio while down-mixing and resampling as necessary.
3535
# Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
3636
file = clean_path(file) # 防止小白拷路径头尾带了空格和"和回车
37+
if os.path.exists(file) == False:
38+
raise RuntimeError(
39+
"You input a wrong audio path that does not exists, please fix it!"
40+
)
3741
out, _ = (
3842
ffmpeg.input(file, threads=0)
3943
.output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr)
4044
.run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True)
4145
)
4246
except Exception as e:
47+
traceback.print_exc()
4348
raise RuntimeError(f"Failed to load audio: {e}")
4449

4550
return np.frombuffer(out, np.float32).flatten()
4651

4752

53+
4854
def clean_path(path_str):
4955
if platform.system() == "Windows":
5056
path_str = path_str.replace("/", "\\")

0 commit comments

Comments
 (0)