chore: code cleanup by ruff suggested
This commit is contained in:
parent
a5f0e911ed
commit
50a089813a
|
@ -24,9 +24,11 @@ def load_model_vocoder(
|
||||||
device='cpu',
|
device='cpu',
|
||||||
config_path = None
|
config_path = None
|
||||||
):
|
):
|
||||||
if config_path is None: config_file = os.path.join(os.path.split(model_path)[0], 'config.yaml')
|
if config_path is None:
|
||||||
else: config_file = config_path
|
config_file = os.path.join(os.path.split(model_path)[0], 'config.yaml')
|
||||||
|
else:
|
||||||
|
config_file = config_path
|
||||||
|
|
||||||
with open(config_file, "r") as config:
|
with open(config_file, "r") as config:
|
||||||
args = yaml.safe_load(config)
|
args = yaml.safe_load(config)
|
||||||
args = DotDict(args)
|
args = DotDict(args)
|
||||||
|
|
|
@ -179,7 +179,8 @@ class Svc(object):
|
||||||
else:
|
else:
|
||||||
self.feature_retrieval=False
|
self.feature_retrieval=False
|
||||||
|
|
||||||
if self.shallow_diffusion : self.nsf_hifigan_enhance = False
|
if self.shallow_diffusion :
|
||||||
|
self.nsf_hifigan_enhance = False
|
||||||
if self.nsf_hifigan_enhance:
|
if self.nsf_hifigan_enhance:
|
||||||
from modules.enhancer import Enhancer
|
from modules.enhancer import Enhancer
|
||||||
self.enhancer = Enhancer('nsf-hifigan', 'pretrain/nsf_hifigan/model',device=self.dev)
|
self.enhancer = Enhancer('nsf-hifigan', 'pretrain/nsf_hifigan/model',device=self.dev)
|
||||||
|
@ -442,7 +443,8 @@ class Svc(object):
|
||||||
datas = [data]
|
datas = [data]
|
||||||
for k,dat in enumerate(datas):
|
for k,dat in enumerate(datas):
|
||||||
per_length = int(np.ceil(len(dat) / audio_sr * self.target_sample)) if clip_seconds!=0 else length
|
per_length = int(np.ceil(len(dat) / audio_sr * self.target_sample)) if clip_seconds!=0 else length
|
||||||
if clip_seconds!=0: print(f'###=====segment clip start, {round(len(dat) / audio_sr, 3)}s======')
|
if clip_seconds!=0:
|
||||||
|
print(f'###=====segment clip start, {round(len(dat) / audio_sr, 3)}s======')
|
||||||
# padd
|
# padd
|
||||||
pad_len = int(audio_sr * pad_seconds)
|
pad_len = int(audio_sr * pad_seconds)
|
||||||
dat = np.concatenate([np.zeros([pad_len]), dat, np.zeros([pad_len])])
|
dat = np.concatenate([np.zeros([pad_len]), dat, np.zeros([pad_len])])
|
||||||
|
|
|
@ -132,8 +132,10 @@ def main():
|
||||||
key = "auto" if auto_predict_f0 else f"{tran}key"
|
key = "auto" if auto_predict_f0 else f"{tran}key"
|
||||||
cluster_name = "" if cluster_infer_ratio == 0 else f"_{cluster_infer_ratio}"
|
cluster_name = "" if cluster_infer_ratio == 0 else f"_{cluster_infer_ratio}"
|
||||||
isdiffusion = "sovits"
|
isdiffusion = "sovits"
|
||||||
if shallow_diffusion : isdiffusion = "sovdiff"
|
if shallow_diffusion :
|
||||||
if only_diffusion : isdiffusion = "diff"
|
isdiffusion = "sovdiff"
|
||||||
|
if only_diffusion :
|
||||||
|
isdiffusion = "diff"
|
||||||
if use_spk_mix:
|
if use_spk_mix:
|
||||||
spk = "spk_mix"
|
spk = "spk_mix"
|
||||||
res_path = f'results/{clean_name}_{key}_{spk}{cluster_name}_{isdiffusion}_{f0p}.{wav_format}'
|
res_path = f'results/{clean_name}_{key}_{spk}{cluster_name}_{isdiffusion}_{f0p}.{wav_format}'
|
||||||
|
|
|
@ -134,12 +134,6 @@ def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
||||||
return acts
|
return acts
|
||||||
|
|
||||||
|
|
||||||
def convert_pad_shape(pad_shape):
|
|
||||||
l = pad_shape[::-1]
|
|
||||||
pad_shape = [item for sublist in l for item in sublist]
|
|
||||||
return pad_shape
|
|
||||||
|
|
||||||
|
|
||||||
def shift_1d(x):
|
def shift_1d(x):
|
||||||
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
||||||
return x
|
return x
|
||||||
|
|
9
train.py
9
train.py
|
@ -1,11 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
|
||||||
|
|
||||||
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
|
||||||
logging.getLogger('numba').setLevel(logging.WARNING)
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import torch.distributed as dist
|
import torch.distributed as dist
|
||||||
|
@ -26,6 +22,9 @@ from models import (
|
||||||
from modules.losses import discriminator_loss, feature_loss, generator_loss, kl_loss
|
from modules.losses import discriminator_loss, feature_loss, generator_loss, kl_loss
|
||||||
from modules.mel_processing import mel_spectrogram_torch, spec_to_mel_torch
|
from modules.mel_processing import mel_spectrogram_torch, spec_to_mel_torch
|
||||||
|
|
||||||
|
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
||||||
|
logging.getLogger('numba').setLevel(logging.WARNING)
|
||||||
|
|
||||||
torch.backends.cudnn.benchmark = True
|
torch.backends.cudnn.benchmark = True
|
||||||
global_step = 0
|
global_step = 0
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
21
webUI.py
21
webUI.py
|
@ -45,7 +45,8 @@ def upload_mix_append_file(files,sfiles):
|
||||||
p = {file:100 for file in file_paths}
|
p = {file:100 for file in file_paths}
|
||||||
return file_paths,mix_model_output1.update(value=json.dumps(p,indent=2))
|
return file_paths,mix_model_output1.update(value=json.dumps(p,indent=2))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug: traceback.print_exc()
|
if debug:
|
||||||
|
traceback.print_exc()
|
||||||
raise gr.Error(e)
|
raise gr.Error(e)
|
||||||
|
|
||||||
def mix_submit_click(js,mode):
|
def mix_submit_click(js,mode):
|
||||||
|
@ -59,16 +60,19 @@ def mix_submit_click(js,mode):
|
||||||
path = mix_model(model_path,mix_rate,mode)
|
path = mix_model(model_path,mix_rate,mode)
|
||||||
return f"成功,文件被保存在了{path}"
|
return f"成功,文件被保存在了{path}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug: traceback.print_exc()
|
if debug:
|
||||||
|
traceback.print_exc()
|
||||||
raise gr.Error(e)
|
raise gr.Error(e)
|
||||||
|
|
||||||
def updata_mix_info(files):
|
def updata_mix_info(files):
|
||||||
try:
|
try:
|
||||||
if files is None : return mix_model_output1.update(value="")
|
if files is None :
|
||||||
|
return mix_model_output1.update(value="")
|
||||||
p = {file.name:100 for file in files}
|
p = {file.name:100 for file in files}
|
||||||
return mix_model_output1.update(value=json.dumps(p,indent=2))
|
return mix_model_output1.update(value=json.dumps(p,indent=2))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug: traceback.print_exc()
|
if debug:
|
||||||
|
traceback.print_exc()
|
||||||
raise gr.Error(e)
|
raise gr.Error(e)
|
||||||
|
|
||||||
def modelAnalysis(model_path,config_path,cluster_model_path,device,enhance,diff_model_path,diff_config_path,only_diffusion,use_spk_mix):
|
def modelAnalysis(model_path,config_path,cluster_model_path,device,enhance,diff_model_path,diff_config_path,only_diffusion,use_spk_mix):
|
||||||
|
@ -108,7 +112,8 @@ def modelAnalysis(model_path,config_path,cluster_model_path,device,enhance,diff_
|
||||||
msg += i + " "
|
msg += i + " "
|
||||||
return sid.update(choices = spks,value=spks[0]), msg
|
return sid.update(choices = spks,value=spks[0]), msg
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug: traceback.print_exc()
|
if debug:
|
||||||
|
traceback.print_exc()
|
||||||
raise gr.Error(e)
|
raise gr.Error(e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,7 +173,8 @@ def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise
|
||||||
soundfile.write(output_file, _audio, model.target_sample, format="wav")
|
soundfile.write(output_file, _audio, model.target_sample, format="wav")
|
||||||
return "Success", output_file
|
return "Success", output_file
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug: traceback.print_exc()
|
if debug:
|
||||||
|
traceback.print_exc()
|
||||||
raise gr.Error(e)
|
raise gr.Error(e)
|
||||||
|
|
||||||
def tts_func(_text,_rate,_voice):
|
def tts_func(_text,_rate,_voice):
|
||||||
|
@ -176,7 +182,8 @@ def tts_func(_text,_rate,_voice):
|
||||||
# voice = "zh-CN-XiaoyiNeural"#女性,较高音
|
# voice = "zh-CN-XiaoyiNeural"#女性,较高音
|
||||||
# voice = "zh-CN-YunxiNeural"#男性
|
# voice = "zh-CN-YunxiNeural"#男性
|
||||||
voice = "zh-CN-YunxiNeural"#男性
|
voice = "zh-CN-YunxiNeural"#男性
|
||||||
if ( _voice == "女" ) : voice = "zh-CN-XiaoyiNeural"
|
if ( _voice == "女" ) :
|
||||||
|
voice = "zh-CN-XiaoyiNeural"
|
||||||
output_file = _text[0:10]+".wav"
|
output_file = _text[0:10]+".wav"
|
||||||
# communicate = edge_tts.Communicate(_text, voice)
|
# communicate = edge_tts.Communicate(_text, voice)
|
||||||
# await communicate.save(output_file)
|
# await communicate.save(output_file)
|
||||||
|
|
Loading…
Reference in New Issue