diff --git a/infer/lib/audio.py b/infer/lib/audio.py index 2c8de5c..13c12f5 100644 --- a/infer/lib/audio.py +++ b/infer/lib/audio.py @@ -53,8 +53,10 @@ 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!") + if os.path.exists(file) == False: + raise RuntimeError( + "You input a wrong audio path that does not exists, please fix it!" + ) try: with open(file, "rb") as f: with BytesIO() as out: diff --git a/infer/modules/uvr5/mdxnet.py b/infer/modules/uvr5/mdxnet.py index c6d0e25..2f246db 100644 --- a/infer/modules/uvr5/mdxnet.py +++ b/infer/modules/uvr5/mdxnet.py @@ -216,26 +216,26 @@ class Predictor: path_other = "%s/%s_others.wav" % (others_root, basename) sf.write(path_vocal, mix - opt, rate) sf.write(path_other, opt, rate) - opt_path_vocal=path_vocal[:-4] + ".%s" % format - opt_path_other=path_other[:-4] + ".%s" % format + opt_path_vocal = path_vocal[:-4] + ".%s" % format + opt_path_other = path_other[:-4] + ".%s" % format if os.path.exists(path_vocal): os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path_vocal, opt_path_vocal) + "ffmpeg -i %s -vn %s -q:a 2 -y" % (path_vocal, opt_path_vocal) ) - if(os.path.exists(opt_path_vocal)): + if os.path.exists(opt_path_vocal): try: os.remove(path_vocal) - except:pass + except: + pass if os.path.exists(path_other): os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path_other, opt_path_other) + "ffmpeg -i %s -vn %s -q:a 2 -y" % (path_other, opt_path_other) ) - if(os.path.exists(opt_path_other)): + if os.path.exists(opt_path_other): try: os.remove(path_other) - except:pass + except: + pass class MDXNetDereverb: @@ -252,5 +252,5 @@ class MDXNetDereverb: self.pred = Predictor(self) self.device = device - def _path_audio_(self, input, vocal_root, others_root, format,is_hp3=False): + def _path_audio_(self, input, vocal_root, others_root, format, is_hp3=False): self.pred.prediction(input, vocal_root, others_root, format) diff --git a/infer/modules/uvr5/modules.py b/infer/modules/uvr5/modules.py index 151176c..bce3cef 100644 --- a/infer/modules/uvr5/modules.py +++ b/infer/modules/uvr5/modules.py @@ -34,7 +34,7 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format os.getenv("weight_uvr5_root"), model_name + ".pth" ), device=config.device, - is_half=config.is_half + is_half=config.is_half, ) is_hp3 = "HP3" in model_name if inp_root != "": @@ -53,7 +53,7 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format ): need_reformat = 0 pre_fun._path_audio_( - inp_path, save_root_ins, save_root_vocal, format0,is_hp3=is_hp3 + inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3 ) done = 1 except: diff --git a/infer/modules/uvr5/vr.py b/infer/modules/uvr5/vr.py index acd165a..d3fbac4 100644 --- a/infer/modules/uvr5/vr.py +++ b/infer/modules/uvr5/vr.py @@ -16,7 +16,7 @@ from infer.lib.uvr5_pack.utils import inference class AudioPre: - def __init__(self, agg, model_path, device, is_half, tta = False): + def __init__(self, agg, model_path, device, is_half, tta=False): self.model_path = model_path self.device = device self.data = { @@ -41,7 +41,9 @@ class AudioPre: self.mp = mp self.model = model - def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac",is_hp3=False): + def _path_audio_( + self, music_file, ins_root=None, vocal_root=None, format="flac", is_hp3=False + ): if ins_root is None and vocal_root is None: return "No save root." name = os.path.basename(music_file) @@ -120,20 +122,22 @@ class AudioPre: else: wav_instrument = spec_utils.cmb_spectrogram_to_wave(y_spec_m, self.mp) logger.info("%s instruments done" % name) - if(is_hp3==True):head="vocal_" - else:head="instrument_" + if is_hp3 == True: + head = "vocal_" + else: + head = "instrument_" if format in ["wav", "flac"]: sf.write( os.path.join( ins_root, - head+"{}_{}.{}".format(name, self.data["agg"], format), + head + "{}_{}.{}".format(name, self.data["agg"], format), ), (np.array(wav_instrument) * 32768).astype("int16"), self.mp.param["sr"], ) # else: path = os.path.join( - ins_root, head+"{}_{}.wav".format(name, self.data["agg"]) + ins_root, head + "{}_{}.wav".format(name, self.data["agg"]) ) sf.write( path, @@ -141,18 +145,18 @@ class AudioPre: self.mp.param["sr"], ) if os.path.exists(path): - opt_format_path=path[:-4] + ".%s" % format - os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path, opt_format_path) - ) + opt_format_path = path[:-4] + ".%s" % format + os.system("ffmpeg -i %s -vn %s -q:a 2 -y" % (path, opt_format_path)) if os.path.exists(opt_format_path): try: os.remove(path) - except:pass + except: + pass if vocal_root is not None: - if(is_hp3==True):head="instrument_" - else:head="vocal_" + if is_hp3 == True: + head = "instrument_" + else: + head = "vocal_" if self.data["high_end_process"].startswith("mirroring"): input_high_end_ = spec_utils.mirroring( self.data["high_end_process"], v_spec_m, input_high_end, self.mp @@ -167,14 +171,14 @@ class AudioPre: sf.write( os.path.join( vocal_root, - head+"{}_{}.{}".format(name, self.data["agg"], format), + head + "{}_{}.{}".format(name, self.data["agg"], format), ), (np.array(wav_vocals) * 32768).astype("int16"), self.mp.param["sr"], ) else: path = os.path.join( - vocal_root, head+"{}_{}.wav".format(name, self.data["agg"]) + vocal_root, head + "{}_{}.wav".format(name, self.data["agg"]) ) sf.write( path, @@ -182,19 +186,17 @@ class AudioPre: self.mp.param["sr"], ) if os.path.exists(path): - opt_format_path=path[:-4] + ".%s" % format - os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path, opt_format_path) - ) + opt_format_path = path[:-4] + ".%s" % format + os.system("ffmpeg -i %s -vn %s -q:a 2 -y" % (path, opt_format_path)) if os.path.exists(opt_format_path): try: os.remove(path) - except:pass + except: + pass class AudioPreDeEcho: - def __init__(self, agg, model_path, device, is_half, tta = False): + def __init__(self, agg, model_path, device, is_half, tta=False): self.model_path = model_path self.device = device self.data = { @@ -221,7 +223,7 @@ class AudioPreDeEcho: self.model = model def _path_audio_( - self, music_file, vocal_root=None, ins_root=None, format="flac",is_hp3=False + self, music_file, vocal_root=None, ins_root=None, format="flac", is_hp3=False ): # 3个VR模型vocal和ins是反的 if ins_root is None and vocal_root is None: return "No save root." @@ -320,15 +322,13 @@ class AudioPreDeEcho: self.mp.param["sr"], ) if os.path.exists(path): - opt_format_path=path[:-4] + ".%s" % format - os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path, opt_format_path) - ) + opt_format_path = path[:-4] + ".%s" % format + os.system("ffmpeg -i %s -vn %s -q:a 2 -y" % (path, opt_format_path)) if os.path.exists(opt_format_path): try: os.remove(path) - except:pass + except: + pass if vocal_root is not None: if self.data["high_end_process"].startswith("mirroring"): input_high_end_ = spec_utils.mirroring( @@ -359,12 +359,10 @@ class AudioPreDeEcho: self.mp.param["sr"], ) if os.path.exists(path): - opt_format_path=path[:-4] + ".%s" % format - os.system( - "ffmpeg -i %s -vn %s -q:a 2 -y" - % (path, opt_format_path) - ) + opt_format_path = path[:-4] + ".%s" % format + os.system("ffmpeg -i %s -vn %s -q:a 2 -y" % (path, opt_format_path)) if os.path.exists(opt_format_path): try: os.remove(path) - except:pass + except: + pass