Add files via upload

This commit is contained in:
RVC-Boss 2023-10-08 18:40:45 +08:00 committed by GitHub
parent 891a81cd8d
commit 5c609190a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,6 @@
import os
import traceback
import librosa import librosa
import numpy as np import numpy as np
import av import av
@ -47,10 +50,12 @@ def audio2(i, o, format, sr):
def load_audio(file, sr): def load_audio(file, sr):
file = (
file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
) # 防止小白拷路径头尾带了空格和"和回车
if(os.path.exists(file)==False):
raise RuntimeError("You input a wrong audio path that does not exists, please fix it!")
try: try:
file = (
file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
) # 防止小白拷路径头尾带了空格和"和回车
with open(file, "rb") as f: with open(file, "rb") as f:
with BytesIO() as out: with BytesIO() as out:
audio2(f, out, "f32le", sr) audio2(f, out, "f32le", sr)
@ -62,5 +67,5 @@ def load_audio(file, sr):
audio = np.mean(audio, -1) audio = np.mean(audio, -1)
return librosa.resample(audio, orig_sr=file[0], target_sr=16000) return librosa.resample(audio, orig_sr=file[0], target_sr=16000)
except Exception as e: except:
raise RuntimeError(f"Failed to load audio: {e}") raise RuntimeError(traceback.format_exc())