Apply Code Formatter Change

This commit is contained in:
Tps-F
2023-08-19 10:57:09 +00:00
committed by github-actions[bot]
parent 2e56c5c600
commit c14721d9c3
3 changed files with 137 additions and 107 deletions

View File

@@ -24,19 +24,19 @@ class VC:
self.if_f0 = None
self.version = None
self.hubert_model = None
self.config = config
def get_vc(self, sid, to_return_protect0, to_return_protect1):
person = f'{os.getenv("weight_root")}/{sid}'
print(f'loading {person}')
print(f"loading {person}")
self.cpt = torch.load(person, map_location="cpu")
self.tgt_sr = self.cpt["config"][-1]
self.cpt["config"][-3] = self.cpt["weight"]["emb_g.weight"].shape[0] # n_spk
self.if_f0 = self.cpt.get("f0", 1)
self.version = self.cpt.get("version", "v1")
to_return_protect0 = {
"visible": self.if_f0 != 0,
"value": to_return_protect0 if self.if_f0 != 0 else 0.5,
@@ -47,16 +47,18 @@ class VC:
"value": to_return_protect1 if self.if_f0 != 0 else 0.33,
"__type__": "update",
}
synthesizer_class = {
("v1", 1): SynthesizerTrnMs256NSFsid,
("v1", 0): SynthesizerTrnMs256NSFsid_nono,
("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
self.net_g.load_state_dict(self.cpt["weight"], strict=False)
@@ -65,23 +67,34 @@ class VC:
self.net_g = self.net_g.half()
else:
self.net_g = self.net_g.float()
self.pipeline = Pipeline(self.tgt_sr, self.config)
n_spk = self.cpt["config"][-3]
index = {
"value": get_index_path_from_model(sid),
"__type__": "update"
}
index = {"value": get_index_path_from_model(sid), "__type__": "update"}
return (
{"visible": True, "maximum": n_spk, "__type__": "update"},
to_return_protect0,
to_return_protect1,
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:
return "You need to upload an audio", None
f0_up_key = int(f0_up_key)
@@ -91,10 +104,10 @@ class VC:
if audio_max > 1:
audio /= audio_max
times = [0, 0, 0]
if self.hubert_model is None:
self.hubert_model = load_hubert(self.config)
file_index = (
(
file_index.strip(" ")
@@ -107,7 +120,7 @@ class VC:
if file_index != ""
else file_index2
) # 防止小白写错,自动帮他替换掉
audio_opt = Pipeline.pipeline(
self.hubert_model,
self.net_g,
@@ -135,28 +148,32 @@ class VC:
if os.path.exists(file_index)
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:
info = traceback.format_exc()
print(info)
return info, (None, None)
def vc_multi(
self,
sid,
dir_path,
opt_root,
paths,
f0_up_key,
f0_method,
file_index,
file_index2,
index_rate,
filter_radius,
resample_sr,
rms_mix_rate,
protect,
format1):
self,
sid,
dir_path,
opt_root,
paths,
f0_up_key,
f0_method,
file_index,
file_index2,
index_rate,
filter_radius,
resample_sr,
rms_mix_rate,
protect,
format1,
):
try:
dir_path = (
dir_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
@@ -165,7 +182,9 @@ class VC:
os.makedirs(opt_root, exist_ok=True)
try:
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:
paths = [path.name for path in paths]
except:
@@ -193,7 +212,8 @@ class VC:
tgt_sr, audio_opt = opt
if format1 in ["wav", "flac"]:
sf.write(
"%s/%s.%s" % (opt_root, os.path.basename(path), format1),
"%s/%s.%s"
% (opt_root, os.path.basename(path), format1),
audio_opt,
tgt_sr,
)
@@ -216,4 +236,3 @@ class VC:
yield "\n".join(infos)
except:
yield traceback.format_exc()