mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2025-03-11 08:15:01 +08:00
Apply Code Formatter Change
This commit is contained in:
parent
2e56c5c600
commit
c14721d9c3
@ -29,7 +29,7 @@ class VC:
|
|||||||
|
|
||||||
def get_vc(self, sid, to_return_protect0, to_return_protect1):
|
def get_vc(self, sid, to_return_protect0, to_return_protect1):
|
||||||
person = f'{os.getenv("weight_root")}/{sid}'
|
person = f'{os.getenv("weight_root")}/{sid}'
|
||||||
print(f'loading {person}')
|
print(f"loading {person}")
|
||||||
|
|
||||||
self.cpt = torch.load(person, map_location="cpu")
|
self.cpt = torch.load(person, map_location="cpu")
|
||||||
self.tgt_sr = self.cpt["config"][-1]
|
self.tgt_sr = self.cpt["config"][-1]
|
||||||
@ -52,10 +52,12 @@ class VC:
|
|||||||
("v1", 1): SynthesizerTrnMs256NSFsid,
|
("v1", 1): SynthesizerTrnMs256NSFsid,
|
||||||
("v1", 0): SynthesizerTrnMs256NSFsid_nono,
|
("v1", 0): SynthesizerTrnMs256NSFsid_nono,
|
||||||
("v2", 1): SynthesizerTrnMs768NSFsid,
|
("v2", 1): SynthesizerTrnMs768NSFsid,
|
||||||
("v2", 0): SynthesizerTrnMs768NSFsid_nono
|
("v2", 0): SynthesizerTrnMs768NSFsid_nono,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.net_g = synthesizer_class.get((self.version, self.if_f0), SynthesizerTrnMs256NSFsid)(*self.cpt["config"], is_half=self.config.is_half)
|
self.net_g = synthesizer_class.get(
|
||||||
|
(self.version, self.if_f0), SynthesizerTrnMs256NSFsid
|
||||||
|
)(*self.cpt["config"], is_half=self.config.is_half)
|
||||||
|
|
||||||
del self.net_g.enc_q
|
del self.net_g.enc_q
|
||||||
|
|
||||||
@ -68,20 +70,31 @@ class VC:
|
|||||||
|
|
||||||
self.pipeline = Pipeline(self.tgt_sr, self.config)
|
self.pipeline = Pipeline(self.tgt_sr, self.config)
|
||||||
n_spk = self.cpt["config"][-3]
|
n_spk = self.cpt["config"][-3]
|
||||||
index = {
|
index = {"value": get_index_path_from_model(sid), "__type__": "update"}
|
||||||
"value": get_index_path_from_model(sid),
|
|
||||||
"__type__": "update"
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
{"visible": True, "maximum": n_spk, "__type__": "update"},
|
{"visible": True, "maximum": n_spk, "__type__": "update"},
|
||||||
to_return_protect0,
|
to_return_protect0,
|
||||||
to_return_protect1,
|
to_return_protect1,
|
||||||
index,
|
index,
|
||||||
index
|
index,
|
||||||
)
|
)
|
||||||
|
|
||||||
def vc_single(self, sid, input_audio_path, f0_up_key, f0_file, f0_method, file_index, file_index2, index_rate, filter_radius, resample_sr, rms_mix_rate, protect):
|
def vc_single(
|
||||||
|
self,
|
||||||
|
sid,
|
||||||
|
input_audio_path,
|
||||||
|
f0_up_key,
|
||||||
|
f0_file,
|
||||||
|
f0_method,
|
||||||
|
file_index,
|
||||||
|
file_index2,
|
||||||
|
index_rate,
|
||||||
|
filter_radius,
|
||||||
|
resample_sr,
|
||||||
|
rms_mix_rate,
|
||||||
|
protect,
|
||||||
|
):
|
||||||
if input_audio_path is None:
|
if input_audio_path is None:
|
||||||
return "You need to upload an audio", None
|
return "You need to upload an audio", None
|
||||||
f0_up_key = int(f0_up_key)
|
f0_up_key = int(f0_up_key)
|
||||||
@ -135,7 +148,10 @@ class VC:
|
|||||||
if os.path.exists(file_index)
|
if os.path.exists(file_index)
|
||||||
else "Index not used."
|
else "Index not used."
|
||||||
)
|
)
|
||||||
return f"Success.\n {index_info}\nTime:\n npy:{times[0]}s, f0:{times[1]}s, infer:{times[2]}s", (self.tgt_sr, audio_opt)
|
return (
|
||||||
|
f"Success.\n {index_info}\nTime:\n npy:{times[0]}s, f0:{times[1]}s, infer:{times[2]}s",
|
||||||
|
(self.tgt_sr, audio_opt),
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
info = traceback.format_exc()
|
info = traceback.format_exc()
|
||||||
print(info)
|
print(info)
|
||||||
@ -156,7 +172,8 @@ class VC:
|
|||||||
resample_sr,
|
resample_sr,
|
||||||
rms_mix_rate,
|
rms_mix_rate,
|
||||||
protect,
|
protect,
|
||||||
format1):
|
format1,
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
dir_path = (
|
dir_path = (
|
||||||
dir_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
dir_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||||
@ -165,7 +182,9 @@ class VC:
|
|||||||
os.makedirs(opt_root, exist_ok=True)
|
os.makedirs(opt_root, exist_ok=True)
|
||||||
try:
|
try:
|
||||||
if dir_path != "":
|
if dir_path != "":
|
||||||
paths = [os.path.join(dir_path, name) for name in os.listdir(dir_path)]
|
paths = [
|
||||||
|
os.path.join(dir_path, name) for name in os.listdir(dir_path)
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
paths = [path.name for path in paths]
|
paths = [path.name for path in paths]
|
||||||
except:
|
except:
|
||||||
@ -193,7 +212,8 @@ class VC:
|
|||||||
tgt_sr, audio_opt = opt
|
tgt_sr, audio_opt = opt
|
||||||
if format1 in ["wav", "flac"]:
|
if format1 in ["wav", "flac"]:
|
||||||
sf.write(
|
sf.write(
|
||||||
"%s/%s.%s" % (opt_root, os.path.basename(path), format1),
|
"%s/%s.%s"
|
||||||
|
% (opt_root, os.path.basename(path), format1),
|
||||||
audio_opt,
|
audio_opt,
|
||||||
tgt_sr,
|
tgt_sr,
|
||||||
)
|
)
|
||||||
@ -216,4 +236,3 @@ class VC:
|
|||||||
yield "\n".join(infos)
|
yield "\n".join(infos)
|
||||||
except:
|
except:
|
||||||
yield traceback.format_exc()
|
yield traceback.format_exc()
|
||||||
|
|
@ -453,4 +453,3 @@ class Pipeline(object):
|
|||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
return audio_opt
|
return audio_opt
|
||||||
|
|
@ -6,7 +6,19 @@ from fairseq import checkpoint_utils
|
|||||||
|
|
||||||
|
|
||||||
def get_index_path_from_model(sid):
|
def get_index_path_from_model(sid):
|
||||||
return next((f for f in [os.path.join(root, name) for root, dirs, files in os.walk(os.getenv("index_root"), topdown=False) for name in files if name.endswith(".index") and "trained" not in name] if sid.split(".")[0] in f), "")
|
return next(
|
||||||
|
(
|
||||||
|
f
|
||||||
|
for f in [
|
||||||
|
os.path.join(root, name)
|
||||||
|
for root, dirs, files in os.walk(os.getenv("index_root"), topdown=False)
|
||||||
|
for name in files
|
||||||
|
if name.endswith(".index") and "trained" not in name
|
||||||
|
]
|
||||||
|
if sid.split(".")[0] in f
|
||||||
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_hubert(config):
|
def load_hubert(config):
|
||||||
|
Loading…
Reference in New Issue
Block a user