mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-04-30 06:22:52 +08:00
修复uvr5识别格式失败报错问题。除非列举不能识别的bad case,否则禁止改动此文件。
修复uvr5识别格式失败报错问题。除非列举不能识别的bad case,否则禁止改动此文件。
This commit is contained in:
parent
cec47ec1f2
commit
e3d792fb56
@ -5,7 +5,7 @@ from tools.i18n.i18n import I18nAuto
|
|||||||
i18n = I18nAuto()
|
i18n = I18nAuto()
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
import librosa
|
import librosa,ffmpeg
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
import torch
|
import torch
|
||||||
import sys
|
import sys
|
||||||
@ -34,18 +34,17 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
|||||||
save_root_ins.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
save_root_ins.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||||
)
|
)
|
||||||
if model_name == "onnx_dereverb_By_FoxJoy":
|
if model_name == "onnx_dereverb_By_FoxJoy":
|
||||||
pre_fun = MDXNetDereverb(15, device)
|
from MDXNet import MDXNetDereverb
|
||||||
|
|
||||||
|
pre_fun = MDXNetDereverb(15)
|
||||||
else:
|
else:
|
||||||
func = AudioPre if "DeEcho" not in model_name else AudioPreDeEcho
|
func = AudioPre if "DeEcho" not in model_name else AudioPreDeEcho
|
||||||
pre_fun = func(
|
pre_fun = func(
|
||||||
agg=int(agg),
|
agg=int(agg),
|
||||||
model_path=os.path.join(
|
model_path=os.path.join(weight_uvr5_root, model_name + ".pth"),
|
||||||
weight_uvr5_root, model_name + ".pth"
|
|
||||||
),
|
|
||||||
device=device,
|
device=device,
|
||||||
is_half=is_half,
|
is_half=is_half,
|
||||||
)
|
)
|
||||||
is_hp3 = "HP3" in model_name
|
|
||||||
if inp_root != "":
|
if inp_root != "":
|
||||||
paths = [os.path.join(inp_root, name) for name in os.listdir(inp_root)]
|
paths = [os.path.join(inp_root, name) for name in os.listdir(inp_root)]
|
||||||
else:
|
else:
|
||||||
@ -53,53 +52,43 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
|||||||
for path in paths:
|
for path in paths:
|
||||||
inp_path = os.path.join(inp_root, path)
|
inp_path = os.path.join(inp_root, path)
|
||||||
if(os.path.isfile(inp_path)==False):continue
|
if(os.path.isfile(inp_path)==False):continue
|
||||||
|
need_reformat = 1
|
||||||
|
done = 0
|
||||||
try:
|
try:
|
||||||
done = 0
|
info = ffmpeg.probe(inp_path, cmd="ffprobe")
|
||||||
try:
|
if (
|
||||||
y, sr = librosa.load(inp_path, sr=None)
|
info["streams"][0]["channels"] == 2
|
||||||
info = sf.info(inp_path)
|
and info["streams"][0]["sample_rate"] == "44100"
|
||||||
channels = info.channels
|
):
|
||||||
if channels == 2 and sr == 44100:
|
need_reformat = 0
|
||||||
need_reformat = 0
|
pre_fun._path_audio_(
|
||||||
pre_fun._path_audio_(
|
inp_path, save_root_ins, save_root_vocal, format0
|
||||||
inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3
|
|
||||||
)
|
|
||||||
done = 1
|
|
||||||
else:
|
|
||||||
need_reformat = 1
|
|
||||||
except:
|
|
||||||
need_reformat = 1
|
|
||||||
traceback.print_exc()
|
|
||||||
if need_reformat == 1:
|
|
||||||
tmp_path = "%s/%s.reformatted.wav" % (
|
|
||||||
os.path.join(os.environ["TEMP"]),
|
|
||||||
os.path.basename(inp_path),
|
|
||||||
)
|
)
|
||||||
y_resampled = librosa.resample(y, sr, 44100)
|
done = 1
|
||||||
sf.write(tmp_path, y_resampled, 44100, "PCM_16")
|
|
||||||
inp_path = tmp_path
|
|
||||||
try:
|
|
||||||
if done == 0:
|
|
||||||
pre_fun._path_audio_(
|
|
||||||
inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3
|
|
||||||
)
|
|
||||||
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
|
||||||
yield "\n".join(infos)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
if done == 0:
|
|
||||||
pre_fun._path_audio_(
|
|
||||||
inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3
|
|
||||||
)
|
|
||||||
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
|
||||||
yield "\n".join(infos)
|
|
||||||
except:
|
|
||||||
infos.append(
|
|
||||||
"%s->%s" % (os.path.basename(inp_path), traceback.format_exc())
|
|
||||||
)
|
|
||||||
yield "\n".join(infos)
|
|
||||||
except:
|
except:
|
||||||
infos.append("Oh my god. %s->%s"%(os.path.basename(inp_path), traceback.format_exc()))
|
need_reformat = 1
|
||||||
|
traceback.print_exc()
|
||||||
|
if need_reformat == 1:
|
||||||
|
tmp_path = "%s/%s.reformatted.wav" % (
|
||||||
|
os.path.join(os.environ["TEMP"]),
|
||||||
|
os.path.basename(inp_path),
|
||||||
|
)
|
||||||
|
os.system(
|
||||||
|
"ffmpeg -i %s -vn -acodec pcm_s16le -ac 2 -ar 44100 %s -y"
|
||||||
|
% (inp_path, tmp_path)
|
||||||
|
)
|
||||||
|
inp_path = tmp_path
|
||||||
|
try:
|
||||||
|
if done == 0:
|
||||||
|
pre_fun._path_audio_(
|
||||||
|
inp_path, save_root_ins, save_root_vocal, format0
|
||||||
|
)
|
||||||
|
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
||||||
|
yield "\n".join(infos)
|
||||||
|
except:
|
||||||
|
infos.append(
|
||||||
|
"%s->%s" % (os.path.basename(inp_path), traceback.format_exc())
|
||||||
|
)
|
||||||
yield "\n".join(infos)
|
yield "\n".join(infos)
|
||||||
except:
|
except:
|
||||||
infos.append(traceback.format_exc())
|
infos.append(traceback.format_exc())
|
||||||
@ -114,12 +103,11 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
|||||||
del pre_fun
|
del pre_fun
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
print("clean_empty_cache")
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
logger.info("Executed torch.cuda.empty_cache()")
|
|
||||||
yield "\n".join(infos)
|
yield "\n".join(infos)
|
||||||
|
|
||||||
|
|
||||||
with gr.Blocks(title="UVR5 WebUI") as app:
|
with gr.Blocks(title="UVR5 WebUI") as app:
|
||||||
gr.Markdown(
|
gr.Markdown(
|
||||||
value=
|
value=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user