mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-09-29 00:30:15 +08:00
chore: change to python syntax\n for higher readibility
This commit is contained in:
parent
fdf794e31d
commit
44499eb5bd
@ -61,11 +61,7 @@ class Text2SemanticDataset(Dataset):
|
||||
)
|
||||
# get dict
|
||||
self.path2 = phoneme_path # "%s/2-name2text.txt"%exp_dir#phoneme_path
|
||||
self.path3 = "%s/3-bert" % (
|
||||
os.path.dirname(
|
||||
phoneme_path,
|
||||
)
|
||||
) # "%s/3-bert"%exp_dir#bert_dir
|
||||
self.path3 = f"{os.path.dirname(phoneme_path)}/3-bert" # "%s/3-bert"%exp_dir#bert_dir
|
||||
self.path6 = semantic_path # "%s/6-name2semantic.tsv"%exp_dir#semantic_path
|
||||
assert os.path.exists(self.path2)
|
||||
assert os.path.exists(self.path6)
|
||||
@ -219,7 +215,7 @@ class Text2SemanticDataset(Dataset):
|
||||
semantic_ids_len = len(semantic_ids)
|
||||
|
||||
flag = 0
|
||||
path_bert = "%s/%s.pt" % (self.path3, item_name)
|
||||
path_bert = f"{self.path3}/{item_name}.pt"
|
||||
if os.path.exists(path_bert) == True:
|
||||
bert_feature = torch.load(path_bert, map_location="cpu")
|
||||
else:
|
||||
|
@ -26,5 +26,5 @@ def write_args(args, path):
|
||||
args_file.write(str(sys.argv))
|
||||
args_file.write("\n==> args:\n")
|
||||
for k, v in sorted(args_dict.items()):
|
||||
args_file.write(" %s: %s\n" % (str(k), str(v)))
|
||||
args_file.write(f" {str(k)}: {str(v)}\n")
|
||||
args_file.close()
|
||||
|
@ -41,7 +41,7 @@ resample_transform_dict = {}
|
||||
|
||||
def resample(audio_tensor, sr0, sr1, device):
|
||||
global resample_transform_dict
|
||||
key = "%s-%s-%s" % (sr0, sr1, str(device))
|
||||
key = f"{sr0}-{sr1}-{str(device)}"
|
||||
if key not in resample_transform_dict:
|
||||
resample_transform_dict[key] = torchaudio.transforms.Resample(sr0, sr1).to(device)
|
||||
return resample_transform_dict[key](audio_tensor)
|
||||
@ -489,7 +489,7 @@ class TTS:
|
||||
path_sovits = self.configs.default_configs[model_version]["vits_weights_path"]
|
||||
|
||||
if if_lora_v3 == True and os.path.exists(path_sovits) == False:
|
||||
info = path_sovits + i18n("SoVITS %s 底模缺失,无法加载相应 LoRA 权重" % model_version)
|
||||
info = path_sovits + i18n(f"SoVITS {model_version} 底模缺失,无法加载相应 LoRA 权重")
|
||||
raise FileExistsError(info)
|
||||
|
||||
# dict_s2 = torch.load(weights_path, map_location=self.configs.device,weights_only=False)
|
||||
@ -608,7 +608,7 @@ class TTS:
|
||||
self.empty_cache()
|
||||
|
||||
self.vocoder = BigVGAN.from_pretrained(
|
||||
"%s/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x",
|
||||
use_cuda_kernel=False,
|
||||
) # if True, RuntimeError: Ninja is required to load C++ extensions
|
||||
# remove weight norm in the model and set to eval mode
|
||||
@ -641,7 +641,7 @@ class TTS:
|
||||
)
|
||||
self.vocoder.remove_weight_norm()
|
||||
state_dict_g = torch.load(
|
||||
"%s/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth",
|
||||
map_location="cpu",
|
||||
weights_only=False,
|
||||
)
|
||||
|
@ -143,7 +143,7 @@ def cut2(inp):
|
||||
@register_method("cut3")
|
||||
def cut3(inp):
|
||||
inp = inp.strip("\n")
|
||||
opts = ["%s" % item for item in inp.strip("。").split("。")]
|
||||
opts = [f"{item}" for item in inp.strip("。").split("。")]
|
||||
opts = [item for item in opts if not set(item).issubset(punctuation)]
|
||||
return "\n".join(opts)
|
||||
|
||||
|
@ -625,18 +625,7 @@ def fbank(
|
||||
# size (num_mel_bins, padded_window_size // 2)
|
||||
# print(num_mel_bins, padded_window_size, sample_frequency, low_freq, high_freq, vtln_low, vtln_high, vtln_warp)
|
||||
|
||||
cache_key = "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s" % (
|
||||
num_mel_bins,
|
||||
padded_window_size,
|
||||
sample_frequency,
|
||||
low_freq,
|
||||
high_freq,
|
||||
vtln_low,
|
||||
vtln_high,
|
||||
vtln_warp,
|
||||
device,
|
||||
dtype,
|
||||
)
|
||||
cache_key = f"{num_mel_bins}-{padded_window_size}-{sample_frequency}-{low_freq}-{high_freq}-{vtln_low}-{vtln_high}-{vtln_warp}-{device}-{dtype}"
|
||||
if cache_key not in cache:
|
||||
mel_energies = get_mel_banks(
|
||||
num_mel_bins,
|
||||
|
@ -505,7 +505,7 @@ def init_bigvgan():
|
||||
from BigVGAN import bigvgan
|
||||
|
||||
bigvgan_model = bigvgan.BigVGAN.from_pretrained(
|
||||
"%s/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x",
|
||||
use_cuda_kernel=False,
|
||||
) # if True, RuntimeError: Ninja is required to load C++ extensions
|
||||
# remove weight norm in the model and set to eval mode
|
||||
@ -533,7 +533,7 @@ def init_hifigan():
|
||||
hifigan_model.eval()
|
||||
hifigan_model.remove_weight_norm()
|
||||
state_dict_g = torch.load(
|
||||
"%s/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth" % (now_dir,), map_location="cpu"
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth", map_location="cpu"
|
||||
)
|
||||
print("loading vocoder", hifigan_model.load_state_dict(state_dict_g))
|
||||
if is_half == True:
|
||||
@ -1042,7 +1042,7 @@ def test_export(
|
||||
wav_gen = wav_gen[:, :, :wav_gen_length]
|
||||
|
||||
audio = wav_gen[0][0].cpu().detach().numpy()
|
||||
logger.info("end bigvgan %s", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
logger.info(f"end bigvgan {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
sr = 24000
|
||||
soundfile.write(output, (audio * 32768).astype(np.int16), sr)
|
||||
|
||||
@ -1115,7 +1115,7 @@ def test_export(
|
||||
wav_gen = torch.cat([wav_gen, zero_wav_torch], 0)
|
||||
|
||||
audio = wav_gen.cpu().detach().numpy()
|
||||
logger.info("end bigvgan %s", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
logger.info(f"end bigvgan {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
soundfile.write(output, (audio * 32768).astype(np.int16), out_sr)
|
||||
|
||||
|
||||
|
@ -235,7 +235,7 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None)
|
||||
is_exist = is_exist_s2gv3 if model_version == "v3" else is_exist_s2gv4
|
||||
path_sovits = path_sovits_v3 if model_version == "v3" else path_sovits_v4
|
||||
if if_lora_v3 == True and is_exist == False:
|
||||
info = path_sovits + "SoVITS %s" % model_version + i18n("底模缺失,无法加载相应 LoRA 权重")
|
||||
info = path_sovits + f"SoVITS {model_version}" + i18n("底模缺失,无法加载相应 LoRA 权重")
|
||||
gr.Warning(info)
|
||||
raise FileExistsError(info)
|
||||
dict_language = dict_language_v1 if version == "v1" else dict_language_v2
|
||||
@ -320,7 +320,7 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None)
|
||||
vq_model = vq_model.to(device)
|
||||
vq_model.eval()
|
||||
if if_lora_v3 == False:
|
||||
print("loading sovits_%s" % model_version, vq_model.load_state_dict(dict_s2["weight"], strict=False))
|
||||
print(f"loading sovits_{model_version}", vq_model.load_state_dict(dict_s2["weight"], strict=False))
|
||||
else:
|
||||
path_sovits = path_sovits_v3 if model_version == "v3" else path_sovits_v4
|
||||
print(
|
||||
@ -335,7 +335,7 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None)
|
||||
init_lora_weights=True,
|
||||
)
|
||||
vq_model.cfm = get_peft_model(vq_model.cfm, lora_config)
|
||||
print("loading sovits_%s_lora%s" % (model_version, lora_rank))
|
||||
print(f"loading sovits_{model_version}_lora{lora_rank}")
|
||||
vq_model.load_state_dict(dict_s2["weight"], strict=False)
|
||||
vq_model.cfm = vq_model.cfm.merge_and_unload()
|
||||
# torch.save(vq_model.state_dict(),"merge_win.pth")
|
||||
@ -442,7 +442,7 @@ def init_bigvgan():
|
||||
from BigVGAN import bigvgan
|
||||
|
||||
bigvgan_model = bigvgan.BigVGAN.from_pretrained(
|
||||
"%s/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x",
|
||||
use_cuda_kernel=False,
|
||||
) # if True, RuntimeError: Ninja is required to load C++ extensions
|
||||
# remove weight norm in the model and set to eval mode
|
||||
@ -472,7 +472,7 @@ def init_hifigan():
|
||||
hifigan_model.eval()
|
||||
hifigan_model.remove_weight_norm()
|
||||
state_dict_g = torch.load(
|
||||
"%s/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth",
|
||||
map_location="cpu",
|
||||
weights_only=False,
|
||||
)
|
||||
@ -508,7 +508,7 @@ resample_transform_dict = {}
|
||||
|
||||
def resample(audio_tensor, sr0, sr1, device):
|
||||
global resample_transform_dict
|
||||
key = "%s-%s-%s" % (sr0, sr1, str(device))
|
||||
key = f"{sr0}-{sr1}-{str(device)}"
|
||||
if key not in resample_transform_dict:
|
||||
resample_transform_dict[key] = torchaudio.transforms.Resample(sr0, sr1).to(device)
|
||||
return resample_transform_dict[key](audio_tensor)
|
||||
@ -1062,7 +1062,7 @@ def cut2(inp):
|
||||
|
||||
def cut3(inp):
|
||||
inp = inp.strip("\n")
|
||||
opts = ["%s" % item for item in inp.strip("。").split("。")]
|
||||
opts = [f"{item}" for item in inp.strip("。").split("。")]
|
||||
opts = [item for item in opts if not set(item).issubset(punctuation)]
|
||||
return "\n".join(opts)
|
||||
|
||||
|
@ -31,7 +31,7 @@ import torch
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
sys.path.append("%s/GPT_SoVITS" % (now_dir))
|
||||
sys.path.append(f"{now_dir}/GPT_SoVITS")
|
||||
|
||||
logging.getLogger("markdown_it").setLevel(logging.ERROR)
|
||||
logging.getLogger("urllib3").setLevel(logging.ERROR)
|
||||
@ -239,7 +239,7 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None)
|
||||
is_exist = is_exist_s2gv3 if model_version == "v3" else is_exist_s2gv4
|
||||
path_sovits = path_sovits_v3 if model_version == "v3" else path_sovits_v4
|
||||
if if_lora_v3 == True and is_exist == False:
|
||||
info = path_sovits + "SoVITS %s" % model_version + i18n("底模缺失,无法加载相应 LoRA 权重")
|
||||
info = path_sovits + f"SoVITS {model_version}" + i18n("底模缺失,无法加载相应 LoRA 权重")
|
||||
gr.Warning(info)
|
||||
raise FileExistsError(info)
|
||||
dict_language = dict_language_v1 if version == "v1" else dict_language_v2
|
||||
|
@ -23,15 +23,15 @@ class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
|
||||
def __init__(self, hparams, version=None, val=False):
|
||||
exp_dir = hparams.exp_dir
|
||||
self.path2 = "%s/2-name2text.txt" % exp_dir
|
||||
self.path4 = "%s/4-cnhubert" % exp_dir
|
||||
self.path5 = "%s/5-wav32k" % exp_dir
|
||||
self.path2 = f"{exp_dir}/2-name2text.txt"
|
||||
self.path4 = f"{exp_dir}/4-cnhubert"
|
||||
self.path5 = f"{exp_dir}/5-wav32k"
|
||||
assert os.path.exists(self.path2)
|
||||
assert os.path.exists(self.path4)
|
||||
assert os.path.exists(self.path5)
|
||||
self.is_v2Pro = version in {"v2Pro", "v2ProPlus"}
|
||||
if self.is_v2Pro:
|
||||
self.path7 = "%s/7-sv_cn" % exp_dir
|
||||
self.path7 = f"{exp_dir}/7-sv_cn"
|
||||
assert os.path.exists(self.path7)
|
||||
names4 = set([name[:-3] for name in list(os.listdir(self.path4))]) # 去除.pt后缀
|
||||
names5 = set(os.listdir(self.path5))
|
||||
@ -85,7 +85,7 @@ class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
skipped_phone += 1
|
||||
continue
|
||||
|
||||
size = os.path.getsize("%s/%s" % (self.path5, audiopath))
|
||||
size = os.path.getsize(f"{self.path5}/{audiopath}")
|
||||
duration = size / self.sampling_rate / 2
|
||||
|
||||
if duration == 0:
|
||||
@ -110,9 +110,9 @@ class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
||||
audiopath, phoneme_ids = audiopath_sid_text
|
||||
text = torch.FloatTensor(phoneme_ids)
|
||||
try:
|
||||
spec, wav = self.get_audio("%s/%s" % (self.path5, audiopath))
|
||||
spec, wav = self.get_audio(f"{self.path5}/{audiopath}")
|
||||
with torch.no_grad():
|
||||
ssl = torch.load("%s/%s.pt" % (self.path4, audiopath), map_location="cpu")
|
||||
ssl = torch.load(f"{self.path4}/{audiopath}.pt", map_location="cpu")
|
||||
if ssl.shape[-1] != spec.shape[-1]:
|
||||
typee = ssl.dtype
|
||||
ssl = F.pad(ssl.float(), (0, 1), mode="replicate").to(typee)
|
||||
|
@ -46,7 +46,7 @@ def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False)
|
||||
global hann_window
|
||||
dtype_device = str(y.dtype) + "_" + str(y.device)
|
||||
# wnsize_dtype_device = str(win_size) + '_' + dtype_device
|
||||
key = "%s-%s-%s-%s-%s" % (dtype_device, n_fft, sampling_rate, hop_size, win_size)
|
||||
key = f"{dtype_device}-{n_fft}-{sampling_rate}-{hop_size}-{win_size}"
|
||||
# if wnsize_dtype_device not in hann_window:
|
||||
if key not in hann_window:
|
||||
# hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(dtype=y.dtype, device=y.device)
|
||||
@ -78,7 +78,7 @@ def spec_to_mel_torch(spec, n_fft, num_mels, sampling_rate, fmin, fmax):
|
||||
global mel_basis
|
||||
dtype_device = str(spec.dtype) + "_" + str(spec.device)
|
||||
# fmax_dtype_device = str(fmax) + '_' + dtype_device
|
||||
key = "%s-%s-%s-%s-%s-%s" % (dtype_device, n_fft, num_mels, sampling_rate, fmin, fmax)
|
||||
key = f"{dtype_device}-{n_fft}-{num_mels}-{sampling_rate}-{fmin}-{fmax}"
|
||||
# if fmax_dtype_device not in mel_basis:
|
||||
if key not in mel_basis:
|
||||
mel = librosa_mel_fn(sr=sampling_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax)
|
||||
@ -99,16 +99,7 @@ def mel_spectrogram_torch(y, n_fft, num_mels, sampling_rate, hop_size, win_size,
|
||||
global mel_basis, hann_window
|
||||
dtype_device = str(y.dtype) + "_" + str(y.device)
|
||||
# fmax_dtype_device = str(fmax) + '_' + dtype_device
|
||||
fmax_dtype_device = "%s-%s-%s-%s-%s-%s-%s-%s" % (
|
||||
dtype_device,
|
||||
n_fft,
|
||||
num_mels,
|
||||
sampling_rate,
|
||||
hop_size,
|
||||
win_size,
|
||||
fmin,
|
||||
fmax,
|
||||
)
|
||||
fmax_dtype_device = f"{dtype_device}-{n_fft}-{num_mels}-{sampling_rate}-{hop_size}-{win_size}-{fmin}-{fmax}"
|
||||
# wnsize_dtype_device = str(win_size) + '_' + dtype_device
|
||||
wnsize_dtype_device = fmax_dtype_device
|
||||
if fmax_dtype_device not in mel_basis:
|
||||
|
@ -12,9 +12,9 @@ i18n = I18nAuto()
|
||||
def my_save(fea, path): #####fix issue: torch.save doesn't support chinese path
|
||||
dir = os.path.dirname(path)
|
||||
name = os.path.basename(path)
|
||||
tmp_path = "%s.pth" % (ttime())
|
||||
tmp_path = f"{ttime()}.pth"
|
||||
torch.save(fea, tmp_path)
|
||||
shutil.move(tmp_path, "%s/%s" % (dir, name))
|
||||
shutil.move(tmp_path, f"{dir}/{name}")
|
||||
|
||||
|
||||
from io import BytesIO
|
||||
@ -47,14 +47,14 @@ def savee(ckpt, name, epoch, steps, hps, model_version=None, lora_rank=None):
|
||||
continue
|
||||
opt["weight"][key] = ckpt[key].half()
|
||||
opt["config"] = hps
|
||||
opt["info"] = "%sepoch_%siteration" % (epoch, steps)
|
||||
opt["info"] = f"{epoch}epoch_{steps}iteration"
|
||||
if lora_rank:
|
||||
opt["lora_rank"] = lora_rank
|
||||
my_save2(opt, "%s/%s.pth" % (hps.save_weight_dir, name), model_version)
|
||||
my_save2(opt, f"{hps.save_weight_dir}/{name}.pth", model_version)
|
||||
elif model_version != None and "Pro" in model_version:
|
||||
my_save2(opt, "%s/%s.pth" % (hps.save_weight_dir, name), model_version)
|
||||
my_save2(opt, f"{hps.save_weight_dir}/{name}.pth", model_version)
|
||||
else:
|
||||
my_save(opt, "%s/%s.pth" % (hps.save_weight_dir, name))
|
||||
my_save(opt, f"{hps.save_weight_dir}/{name}.pth")
|
||||
return "Success."
|
||||
except:
|
||||
return traceback.format_exc()
|
||||
|
@ -44,7 +44,7 @@ def load_checkpoint(checkpoint_path, model, optimizer=None, skip_optimizer=False
|
||||
)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
print("error, %s is not in the checkpoint" % k) # shape不对也会,比如text_embedding当cleaner修改时
|
||||
print(f"error, {k} is not in the checkpoint") # shape不对也会,比如text_embedding当cleaner修改时
|
||||
new_state_dict[k] = v
|
||||
if hasattr(model, "module"):
|
||||
model.module.load_state_dict(new_state_dict)
|
||||
@ -67,9 +67,9 @@ from time import time as ttime
|
||||
def my_save(fea, path): #####fix issue: torch.save doesn't support chinese path
|
||||
dir = os.path.dirname(path)
|
||||
name = os.path.basename(path)
|
||||
tmp_path = "%s.pth" % (ttime())
|
||||
tmp_path = f"{ttime()}.pth"
|
||||
torch.save(fea, tmp_path)
|
||||
shutil.move(tmp_path, "%s/%s" % (dir, name))
|
||||
shutil.move(tmp_path, f"{dir}/{name}")
|
||||
|
||||
|
||||
def save_checkpoint(model, optimizer, learning_rate, iteration, checkpoint_path):
|
||||
|
10
api.py
10
api.py
@ -147,7 +147,7 @@ import sys
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
sys.path.append("%s/GPT_SoVITS" % (now_dir))
|
||||
sys.path.append(f"{now_dir}/GPT_SoVITS")
|
||||
|
||||
import signal
|
||||
from text.LangSegmenter import LangSegmenter
|
||||
@ -239,7 +239,7 @@ def init_bigvgan():
|
||||
from BigVGAN import bigvgan
|
||||
|
||||
bigvgan_model = bigvgan.BigVGAN.from_pretrained(
|
||||
"%s/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/models--nvidia--bigvgan_v2_24khz_100band_256x",
|
||||
use_cuda_kernel=False,
|
||||
) # if True, RuntimeError: Ninja is required to load C++ extensions
|
||||
# remove weight norm in the model and set to eval mode
|
||||
@ -268,7 +268,7 @@ def init_hifigan():
|
||||
hifigan_model.eval()
|
||||
hifigan_model.remove_weight_norm()
|
||||
state_dict_g = torch.load(
|
||||
"%s/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth" % (now_dir,),
|
||||
f"{now_dir}/GPT_SoVITS/pretrained_models/gsv-v4-pretrained/vocoder.pth",
|
||||
map_location="cpu",
|
||||
weights_only=False,
|
||||
)
|
||||
@ -292,7 +292,7 @@ resample_transform_dict = {}
|
||||
|
||||
def resample(audio_tensor, sr0, sr1, device):
|
||||
global resample_transform_dict
|
||||
key = "%s-%s-%s" % (sr0, sr1, str(device))
|
||||
key = f"{sr0}-{sr1}-{str(device)}"
|
||||
if key not in resample_transform_dict:
|
||||
resample_transform_dict[key] = torchaudio.transforms.Resample(sr0, sr1).to(device)
|
||||
return resample_transform_dict[key](audio_tensor)
|
||||
@ -391,7 +391,7 @@ def get_sovits_weights(sovits_path):
|
||||
path_sovits = path_sovits_v3 if model_version == "v3" else path_sovits_v4
|
||||
|
||||
if if_lora_v3 == True and is_exist == False:
|
||||
logger.info("SoVITS %s 底模缺失,无法加载相应 LoRA 权重" % model_version)
|
||||
logger.info(f"SoVITS {model_version} 底模缺失,无法加载相应 LoRA 权重")
|
||||
|
||||
dict_s2 = load_sovits_new(sovits_path)
|
||||
hps = dict_s2["config"]
|
||||
|
@ -105,7 +105,7 @@ from typing import Generator
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
sys.path.append("%s/GPT_SoVITS" % (now_dir))
|
||||
sys.path.append(f"{now_dir}/GPT_SoVITS")
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
|
@ -93,7 +93,7 @@ def get_weights_names():
|
||||
continue
|
||||
for name in os.listdir(path):
|
||||
if name.endswith(".pth"):
|
||||
SoVITS_names.append("%s/%s" % (path, name))
|
||||
SoVITS_names.append(f"{path}/{name}")
|
||||
if not SoVITS_names:
|
||||
SoVITS_names = [""]
|
||||
GPT_names = []
|
||||
@ -105,7 +105,7 @@ def get_weights_names():
|
||||
continue
|
||||
for name in os.listdir(path):
|
||||
if name.endswith(".ckpt"):
|
||||
GPT_names.append("%s/%s" % (path, name))
|
||||
GPT_names.append(f"{path}/{name}")
|
||||
SoVITS_names = sorted(SoVITS_names, key=custom_sort_key)
|
||||
GPT_names = sorted(GPT_names, key=custom_sort_key)
|
||||
if not GPT_names:
|
||||
|
@ -16,7 +16,7 @@ from models.model import APNet_BWE_Model
|
||||
class AP_BWE:
|
||||
def __init__(self, device, DictToAttrRecursive, checkpoint_file=None):
|
||||
if checkpoint_file == None:
|
||||
checkpoint_file = "%s/24kto48k/g_24kto48k.zip" % (AP_BWE_main_dir_path)
|
||||
checkpoint_file = f"{AP_BWE_main_dir_path}/24kto48k/g_24kto48k.zip"
|
||||
if os.path.exists(checkpoint_file) == False:
|
||||
raise FileNotFoundError
|
||||
config_file = os.path.join(os.path.split(checkpoint_file)[0], "config.json")
|
||||
|
@ -17,7 +17,7 @@ def execute_denoise(input_folder, output_folder):
|
||||
# print(list(os.listdir(input_folder).sort()))
|
||||
for name in tqdm(os.listdir(input_folder)):
|
||||
try:
|
||||
ans("%s/%s" % (input_folder, name), output_path="%s/%s" % (output_folder, name))
|
||||
ans(f"{input_folder}/{name}", output_path=f"{output_folder}/{name}")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
|
@ -103,7 +103,7 @@ def check_details(path_list=None, is_train=False, is_dataset_processing=False):
|
||||
wav_name = clean_path(wav_name)
|
||||
if audio_path != "" and audio_path != None:
|
||||
wav_name = os.path.basename(wav_name)
|
||||
wav_path = "%s/%s" % (audio_path, wav_name)
|
||||
wav_path = f"{audio_path}/{wav_name}"
|
||||
else:
|
||||
wav_path = wav_name
|
||||
if os.path.exists(wav_path):
|
||||
|
@ -40,7 +40,7 @@ def slice(inp, opt_root, threshold, min_length, min_interval, hop_size, max_sil_
|
||||
chunk /= tmp_max
|
||||
chunk = (chunk / tmp_max * (_max * alpha)) + (1 - alpha) * chunk
|
||||
wavfile.write(
|
||||
"%s/%s_%010d_%010d.wav" % (opt_root, name, start, end),
|
||||
f"{opt_root}/{name}_{start:010d}_{end:010d}.wav",
|
||||
32000,
|
||||
# chunk.astype(np.float32),
|
||||
(chunk * 32767).astype(np.int16),
|
||||
|
@ -219,7 +219,7 @@ def main():
|
||||
soundfile.write(
|
||||
os.path.join(
|
||||
out,
|
||||
"%s_%d.wav" % (os.path.basename(args.audio).rsplit(".", maxsplit=1)[0], i),
|
||||
f"{os.path.basename(args.audio).rsplit('.', maxsplit=1)[0]}_{i}.wav",
|
||||
),
|
||||
chunk,
|
||||
sr,
|
||||
|
@ -92,19 +92,16 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
||||
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),
|
||||
)
|
||||
tmp_path = f"{os.path.join(os.environ['TEMP'])}/{os.path.basename(inp_path)}.reformatted.wav"
|
||||
os.system(f'ffmpeg -i "{inp_path}" -vn -acodec pcm_s16le -ac 2 -ar 44100 "{tmp_path}" -y')
|
||||
inp_path = tmp_path
|
||||
try:
|
||||
if done == 0:
|
||||
pre_fun._path_audio_(inp_path, save_root_ins, save_root_vocal, format0, is_hp3)
|
||||
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
||||
infos.append(f"{os.path.basename(inp_path)}->Success")
|
||||
yield "\n".join(infos)
|
||||
except:
|
||||
infos.append("%s->%s" % (os.path.basename(inp_path), traceback.format_exc()))
|
||||
infos.append(f"{os.path.basename(inp_path)}->{traceback.format_exc()}")
|
||||
yield "\n".join(infos)
|
||||
except:
|
||||
infos.append(traceback.format_exc())
|
||||
|
471
webui.py
471
webui.py
@ -25,7 +25,7 @@ if os.path.exists(tmp):
|
||||
for name in os.listdir(tmp):
|
||||
if name == "jieba.cache":
|
||||
continue
|
||||
path = "%s/%s" % (tmp, name)
|
||||
path = f"{tmp}/{name}"
|
||||
delete = os.remove if os.path.isfile(path) else shutil.rmtree
|
||||
try:
|
||||
delete(path)
|
||||
@ -40,18 +40,17 @@ for path in site.getsitepackages():
|
||||
if "packages" in path:
|
||||
site_packages_roots.append(path)
|
||||
if site_packages_roots == []:
|
||||
site_packages_roots = ["%s/runtime/Lib/site-packages" % now_dir]
|
||||
site_packages_roots = [f"{now_dir}/runtime/Lib/site-packages"]
|
||||
# os.environ["OPENBLAS_NUM_THREADS"] = "4"
|
||||
os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
|
||||
os.environ["all_proxy"] = ""
|
||||
for site_packages_root in site_packages_roots:
|
||||
if os.path.exists(site_packages_root):
|
||||
try:
|
||||
with open("%s/users.pth" % (site_packages_root), "w") as f:
|
||||
with open(f"{site_packages_root}/users.pth", "w") as f:
|
||||
f.write(
|
||||
# "%s\n%s/runtime\n%s/tools\n%s/tools/asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
|
||||
"%s\n%s/GPT_SoVITS/BigVGAN\n%s/tools\n%s/tools/asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
|
||||
% (now_dir, now_dir, now_dir, now_dir, now_dir, now_dir)
|
||||
f"{now_dir}\n{now_dir}/GPT_SoVITS/BigVGAN\n{now_dir}/tools\n{now_dir}/tools/asr\n{now_dir}/GPT_SoVITS\n{now_dir}/tools/uvr5"
|
||||
)
|
||||
break
|
||||
except PermissionError:
|
||||
@ -136,6 +135,159 @@ def set_default():
|
||||
default_batch_size_s1 = max(1, default_batch_size_s1)
|
||||
default_max_batch_size = default_batch_size * 3
|
||||
|
||||
# ==================== DRY UTILITY FUNCTIONS ====================
|
||||
|
||||
class ProcessManager:
|
||||
"""Centralized process management to eliminate repetitive code"""
|
||||
|
||||
def __init__(self):
|
||||
self.processes = {}
|
||||
|
||||
def create_process(self, process_name, cmd, wait=False, env_updates=None):
|
||||
"""Create and manage a process with consistent UI updates"""
|
||||
if self.processes.get(process_name) is None:
|
||||
if env_updates:
|
||||
os.environ.update(env_updates)
|
||||
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
self.processes[process_name] = p
|
||||
|
||||
if wait:
|
||||
p.wait()
|
||||
self.processes[process_name] = None
|
||||
|
||||
return True
|
||||
return False
|
||||
|
||||
def kill_process(self, process_name, process_display_name=""):
|
||||
"""Kill a process with consistent error handling"""
|
||||
if self.processes.get(process_name) is not None:
|
||||
kill_process(self.processes[process_name].pid, process_display_name)
|
||||
self.processes[process_name] = None
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_process_status(self, process_name):
|
||||
"""Get current process status"""
|
||||
return self.processes.get(process_name)
|
||||
|
||||
# Global process manager
|
||||
process_manager = ProcessManager()
|
||||
|
||||
def create_ui_yield(process_name, status, visible_states=None):
|
||||
"""Create consistent UI yield patterns"""
|
||||
if visible_states is None:
|
||||
visible_states = {"opened": (False, True), "closed": (True, False), "finish": (True, False), "occupy": (False, True)}
|
||||
|
||||
visible_open, visible_close = visible_states.get(status, (True, False))
|
||||
|
||||
return (
|
||||
process_info(process_name, status),
|
||||
{"__type__": "update", "visible": visible_open},
|
||||
{"__type__": "update", "visible": visible_close},
|
||||
)
|
||||
|
||||
def create_command_builder():
|
||||
"""Factory for building subprocess commands"""
|
||||
class CommandBuilder:
|
||||
def __init__(self):
|
||||
self.base_cmd = f'"{python_exec}" -s'
|
||||
|
||||
def build(self, script_path, *args):
|
||||
"""Build a command with consistent formatting"""
|
||||
cmd_parts = [self.base_cmd, script_path]
|
||||
cmd_parts.extend(str(arg) for arg in args)
|
||||
return " ".join(cmd_parts)
|
||||
|
||||
def build_with_paths(self, script_path, *paths):
|
||||
"""Build command with quoted paths"""
|
||||
cmd_parts = [self.base_cmd, script_path]
|
||||
cmd_parts.extend(f'"{path}"' for path in paths)
|
||||
return " ".join(cmd_parts)
|
||||
|
||||
return CommandBuilder()
|
||||
|
||||
# Global command builder
|
||||
cmd_builder = create_command_builder()
|
||||
|
||||
def setup_gpu_environment(gpu_numbers, is_half_flag=None):
|
||||
"""Setup GPU environment variables consistently"""
|
||||
env_updates = {
|
||||
"_CUDA_VISIBLE_DEVICES": fix_gpu_numbers(gpu_numbers.replace("-", ",")),
|
||||
}
|
||||
if is_half_flag is not None:
|
||||
env_updates["is_half"] = str(is_half_flag)
|
||||
return env_updates
|
||||
|
||||
def create_multi_gpu_config(gpu_numbers, base_config, script_path):
|
||||
"""Create configuration for multi-GPU processing"""
|
||||
gpu_names = gpu_numbers.split("-")
|
||||
all_parts = len(gpu_names)
|
||||
processes = []
|
||||
|
||||
for i_part in range(all_parts):
|
||||
config = base_config.copy()
|
||||
config.update({
|
||||
"i_part": str(i_part),
|
||||
"all_parts": str(all_parts),
|
||||
"_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
|
||||
})
|
||||
os.environ.update(config)
|
||||
|
||||
cmd = cmd_builder.build(script_path)
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
processes.append(p)
|
||||
|
||||
return processes
|
||||
|
||||
def merge_output_files(opt_dir, file_pattern, output_file, header=None):
|
||||
"""Merge multiple output files into a single file"""
|
||||
opt = []
|
||||
if header:
|
||||
opt.append(header)
|
||||
|
||||
all_parts = len([f for f in os.listdir(opt_dir) if f.startswith(file_pattern.split("-")[0])])
|
||||
|
||||
for i_part in range(all_parts):
|
||||
file_path = f"{opt_dir}/{file_pattern.format(i_part)}"
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, "r", encoding="utf8") as f:
|
||||
content = f.read().strip("\n").split("\n")
|
||||
opt.extend(content)
|
||||
os.remove(file_path)
|
||||
|
||||
with open(output_file, "w", encoding="utf8") as f:
|
||||
f.write("\n".join(opt) + "\n")
|
||||
|
||||
return opt
|
||||
|
||||
# ==================== END DRY UTILITY FUNCTIONS ====================
|
||||
|
||||
def create_process_handler(process_name, process_display_name, script_path, env_updates=None, wait=False, additional_args=None):
|
||||
"""Generic process handler to eliminate repetitive open/close patterns"""
|
||||
|
||||
def open_process(*args):
|
||||
process_var = globals().get(f"p_{process_name}")
|
||||
|
||||
if process_var is None:
|
||||
cmd = cmd_builder.build(script_path, *(additional_args or []))
|
||||
|
||||
if process_manager.create_process(process_name, cmd, wait=wait, env_updates=env_updates):
|
||||
yield create_ui_yield(process_display_name, "opened")
|
||||
globals()[f"p_{process_name}"] = process_manager.get_process_status(process_name)
|
||||
else:
|
||||
yield create_ui_yield(process_display_name, "occupy")
|
||||
else:
|
||||
yield create_ui_yield(process_display_name, "occupy")
|
||||
|
||||
def close_process():
|
||||
if process_manager.kill_process(process_name, process_display_name):
|
||||
globals()[f"p_{process_name}"] = None
|
||||
return create_ui_yield(process_display_name, "closed")
|
||||
|
||||
return open_process, close_process
|
||||
|
||||
set_default()
|
||||
|
||||
@ -234,7 +386,7 @@ system = platform.system()
|
||||
|
||||
def kill_process(pid, process_name=""):
|
||||
if system == "Windows":
|
||||
cmd = "taskkill /t /f /pid %s" % pid
|
||||
cmd = f"taskkill /t /f /pid {pid}"
|
||||
# os.system(cmd)
|
||||
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
else:
|
||||
@ -273,27 +425,17 @@ def change_label(path_list):
|
||||
if p_label is None:
|
||||
check_for_existance([path_list])
|
||||
path_list = my_utils.clean_path(path_list)
|
||||
cmd = '"%s" -s tools/subfix_webui.py --load_list "%s" --webui_port %s --is_share %s' % (
|
||||
python_exec,
|
||||
path_list,
|
||||
webui_port_subfix,
|
||||
is_share,
|
||||
)
|
||||
yield (
|
||||
process_info(process_name_subfix, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
)
|
||||
print(cmd)
|
||||
p_label = Popen(cmd, shell=True)
|
||||
cmd = cmd_builder.build_with_paths("tools/subfix_webui.py", path_list) + f" --webui_port {webui_port_subfix} --is_share {is_share}"
|
||||
|
||||
if process_manager.create_process("label", cmd):
|
||||
yield create_ui_yield(process_name_subfix, "opened")
|
||||
p_label = process_manager.get_process_status("label")
|
||||
else:
|
||||
yield create_ui_yield(process_name_subfix, "occupy")
|
||||
else:
|
||||
kill_process(p_label.pid, process_name_subfix)
|
||||
process_manager.kill_process("label", process_name_subfix)
|
||||
p_label = None
|
||||
yield (
|
||||
process_info(process_name_subfix, "closed"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
)
|
||||
yield create_ui_yield(process_name_subfix, "closed")
|
||||
|
||||
|
||||
process_name_uvr5 = i18n("人声分离WebUI")
|
||||
@ -302,28 +444,17 @@ process_name_uvr5 = i18n("人声分离WebUI")
|
||||
def change_uvr5():
|
||||
global p_uvr5
|
||||
if p_uvr5 is None:
|
||||
cmd = '"%s" -s tools/uvr5/webui.py "%s" %s %s %s' % (
|
||||
python_exec,
|
||||
infer_device,
|
||||
is_half,
|
||||
webui_port_uvr5,
|
||||
is_share,
|
||||
)
|
||||
yield (
|
||||
process_info(process_name_uvr5, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
)
|
||||
print(cmd)
|
||||
p_uvr5 = Popen(cmd, shell=True)
|
||||
cmd = cmd_builder.build("tools/uvr5/webui.py", infer_device, is_half, webui_port_uvr5, is_share)
|
||||
|
||||
if process_manager.create_process("uvr5", cmd):
|
||||
yield create_ui_yield(process_name_uvr5, "opened")
|
||||
p_uvr5 = process_manager.get_process_status("uvr5")
|
||||
else:
|
||||
yield create_ui_yield(process_name_uvr5, "occupy")
|
||||
else:
|
||||
kill_process(p_uvr5.pid, process_name_uvr5)
|
||||
process_manager.kill_process("uvr5", process_name_uvr5)
|
||||
p_uvr5 = None
|
||||
yield (
|
||||
process_info(process_name_uvr5, "closed"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
)
|
||||
yield create_ui_yield(process_name_uvr5, "closed")
|
||||
|
||||
|
||||
process_name_tts = i18n("TTS推理WebUI")
|
||||
@ -331,37 +462,30 @@ process_name_tts = i18n("TTS推理WebUI")
|
||||
|
||||
def change_tts_inference(bert_path, cnhubert_base_path, gpu_number, gpt_path, sovits_path, batched_infer_enabled):
|
||||
global p_tts_inference
|
||||
if batched_infer_enabled:
|
||||
cmd = '"%s" -s GPT_SoVITS/inference_webui_fast.py "%s"' % (python_exec, language)
|
||||
else:
|
||||
cmd = '"%s" -s GPT_SoVITS/inference_webui.py "%s"' % (python_exec, language)
|
||||
# #####v3暂不支持加速推理
|
||||
# if version=="v3":
|
||||
# cmd = '"%s" GPT_SoVITS/inference_webui.py "%s"'%(python_exec, language)
|
||||
script = "GPT_SoVITS/inference_webui_fast.py" if batched_infer_enabled else "GPT_SoVITS/inference_webui.py"
|
||||
cmd = cmd_builder.build_with_paths(script, language)
|
||||
|
||||
if p_tts_inference is None:
|
||||
os.environ["gpt_path"] = gpt_path
|
||||
os.environ["sovits_path"] = sovits_path
|
||||
os.environ["cnhubert_base_path"] = cnhubert_base_path
|
||||
os.environ["bert_path"] = bert_path
|
||||
os.environ["_CUDA_VISIBLE_DEVICES"] = fix_gpu_number(gpu_number)
|
||||
os.environ["is_half"] = str(is_half)
|
||||
os.environ["infer_ttswebui"] = str(webui_port_infer_tts)
|
||||
os.environ["is_share"] = str(is_share)
|
||||
yield (
|
||||
process_info(process_name_tts, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
)
|
||||
print(cmd)
|
||||
p_tts_inference = Popen(cmd, shell=True)
|
||||
env_updates = {
|
||||
"gpt_path": gpt_path,
|
||||
"sovits_path": sovits_path,
|
||||
"cnhubert_base_path": cnhubert_base_path,
|
||||
"bert_path": bert_path,
|
||||
"_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_number),
|
||||
"is_half": str(is_half),
|
||||
"infer_ttswebui": str(webui_port_infer_tts),
|
||||
"is_share": str(is_share),
|
||||
}
|
||||
|
||||
if process_manager.create_process("tts_inference", cmd, env_updates=env_updates):
|
||||
yield create_ui_yield(process_name_tts, "opened")
|
||||
p_tts_inference = process_manager.get_process_status("tts_inference")
|
||||
else:
|
||||
yield create_ui_yield(process_name_tts, "occupy")
|
||||
else:
|
||||
kill_process(p_tts_inference.pid, process_name_tts)
|
||||
process_manager.kill_process("tts_inference", process_name_tts)
|
||||
p_tts_inference = None
|
||||
yield (
|
||||
process_info(process_name_tts, "closed"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
)
|
||||
yield create_ui_yield(process_name_tts, "closed")
|
||||
|
||||
|
||||
from tools.asr.config import asr_dict
|
||||
@ -375,56 +499,32 @@ def open_asr(asr_inp_dir, asr_opt_dir, asr_model, asr_model_size, asr_lang, asr_
|
||||
asr_inp_dir = my_utils.clean_path(asr_inp_dir)
|
||||
asr_opt_dir = my_utils.clean_path(asr_opt_dir)
|
||||
check_for_existance([asr_inp_dir])
|
||||
cmd = f'"{python_exec}" -s tools/asr/{asr_dict[asr_model]["path"]}'
|
||||
cmd += f' -i "{asr_inp_dir}"'
|
||||
cmd += f' -o "{asr_opt_dir}"'
|
||||
cmd += f" -s {asr_model_size}"
|
||||
cmd += f" -l {asr_lang}"
|
||||
cmd += f" -p {asr_precision}"
|
||||
|
||||
cmd = cmd_builder.build("tools/asr/" + asr_dict[asr_model]["path"])
|
||||
cmd += f' -i "{asr_inp_dir}" -o "{asr_opt_dir}" -s {asr_model_size} -l {asr_lang} -p {asr_precision}'
|
||||
|
||||
output_file_name = os.path.basename(asr_inp_dir)
|
||||
output_folder = asr_opt_dir or "output/asr_opt"
|
||||
output_file_path = os.path.abspath(f"{output_folder}/{output_file_name}.list")
|
||||
yield (
|
||||
process_info(process_name_asr, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
)
|
||||
print(cmd)
|
||||
p_asr = Popen(cmd, shell=True)
|
||||
p_asr.wait()
|
||||
|
||||
yield create_ui_yield(process_name_asr, "opened") + ({"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"})
|
||||
|
||||
if process_manager.create_process("asr", cmd, wait=True):
|
||||
yield create_ui_yield(process_name_asr, "finish") + (
|
||||
{"__type__": "update", "value": output_file_path},
|
||||
{"__type__": "update", "value": output_file_path},
|
||||
{"__type__": "update", "value": asr_inp_dir},
|
||||
)
|
||||
p_asr = None
|
||||
yield (
|
||||
process_info(process_name_asr, "finish"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "value": output_file_path},
|
||||
{"__type__": "update", "value": output_file_path},
|
||||
{"__type__": "update", "value": asr_inp_dir},
|
||||
)
|
||||
else:
|
||||
yield (
|
||||
process_info(process_name_asr, "occupy"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
)
|
||||
yield create_ui_yield(process_name_asr, "occupy") + ({"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"})
|
||||
|
||||
|
||||
def close_asr():
|
||||
global p_asr
|
||||
if p_asr is not None:
|
||||
kill_process(p_asr.pid, process_name_asr)
|
||||
if process_manager.kill_process("asr", process_name_asr):
|
||||
p_asr = None
|
||||
return (
|
||||
process_info(process_name_asr, "closed"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
)
|
||||
return create_ui_yield(process_name_asr, "closed")
|
||||
|
||||
|
||||
process_name_denoise = i18n("语音降噪")
|
||||
@ -436,51 +536,27 @@ def open_denoise(denoise_inp_dir, denoise_opt_dir):
|
||||
denoise_inp_dir = my_utils.clean_path(denoise_inp_dir)
|
||||
denoise_opt_dir = my_utils.clean_path(denoise_opt_dir)
|
||||
check_for_existance([denoise_inp_dir])
|
||||
cmd = '"%s" -s tools/cmd-denoise.py -i "%s" -o "%s" -p %s' % (
|
||||
python_exec,
|
||||
denoise_inp_dir,
|
||||
denoise_opt_dir,
|
||||
"float16" if is_half == True else "float32",
|
||||
)
|
||||
|
||||
yield (
|
||||
process_info(process_name_denoise, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
)
|
||||
print(cmd)
|
||||
p_denoise = Popen(cmd, shell=True)
|
||||
p_denoise.wait()
|
||||
precision = "float16" if is_half == True else "float32"
|
||||
cmd = cmd_builder.build_with_paths("tools/cmd-denoise.py", denoise_inp_dir, denoise_opt_dir) + f" -p {precision}"
|
||||
|
||||
yield create_ui_yield(process_name_denoise, "opened") + ({"__type__": "update"}, {"__type__": "update"})
|
||||
|
||||
if process_manager.create_process("denoise", cmd, wait=True):
|
||||
yield create_ui_yield(process_name_denoise, "finish") + (
|
||||
{"__type__": "update", "value": denoise_opt_dir},
|
||||
{"__type__": "update", "value": denoise_opt_dir},
|
||||
)
|
||||
p_denoise = None
|
||||
yield (
|
||||
process_info(process_name_denoise, "finish"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "value": denoise_opt_dir},
|
||||
{"__type__": "update", "value": denoise_opt_dir},
|
||||
)
|
||||
else:
|
||||
yield (
|
||||
process_info(process_name_denoise, "occupy"),
|
||||
{"__type__": "update", "visible": False},
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update"},
|
||||
{"__type__": "update"},
|
||||
)
|
||||
yield create_ui_yield(process_name_denoise, "occupy") + ({"__type__": "update"}, {"__type__": "update"})
|
||||
|
||||
|
||||
def close_denoise():
|
||||
global p_denoise
|
||||
if p_denoise is not None:
|
||||
kill_process(p_denoise.pid, process_name_denoise)
|
||||
if process_manager.kill_process("denoise", process_name_denoise):
|
||||
p_denoise = None
|
||||
return (
|
||||
process_info(process_name_denoise, "closed"),
|
||||
{"__type__": "update", "visible": True},
|
||||
{"__type__": "update", "visible": False},
|
||||
)
|
||||
return create_ui_yield(process_name_denoise, "closed")
|
||||
|
||||
|
||||
p_train_SoVITS = None
|
||||
@ -513,8 +589,8 @@ def open1Ba(
|
||||
with open(config_file) as f:
|
||||
data = f.read()
|
||||
data = json.loads(data)
|
||||
s2_dir = "%s/%s" % (exp_root, exp_name)
|
||||
os.makedirs("%s/logs_s2_%s" % (s2_dir, version), exist_ok=True)
|
||||
s2_dir = f"{exp_root}/{exp_name}"
|
||||
os.makedirs(f"{s2_dir}/logs_s2_{version}", exist_ok=True)
|
||||
if check_for_existance([s2_dir], is_train=True):
|
||||
check_details([s2_dir], is_train=True)
|
||||
if is_half == False:
|
||||
@ -536,13 +612,13 @@ def open1Ba(
|
||||
data["save_weight_dir"] = SoVITS_weight_version2root[version]
|
||||
data["name"] = exp_name
|
||||
data["version"] = version
|
||||
tmp_config_path = "%s/tmp_s2.json" % tmp
|
||||
tmp_config_path = f"{tmp}/tmp_s2.json"
|
||||
with open(tmp_config_path, "w") as f:
|
||||
f.write(json.dumps(data))
|
||||
if version in ["v1", "v2", "v2Pro", "v2ProPlus"]:
|
||||
cmd = '"%s" -s GPT_SoVITS/s2_train.py --config "%s"' % (python_exec, tmp_config_path)
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/s2_train.py --config "{tmp_config_path}"'
|
||||
else:
|
||||
cmd = '"%s" -s GPT_SoVITS/s2_train_v3_lora.py --config "%s"' % (python_exec, tmp_config_path)
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/s2_train_v3_lora.py --config "{tmp_config_path}"'
|
||||
yield (
|
||||
process_info(process_name_sovits, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
@ -607,8 +683,8 @@ def open1Bb(
|
||||
) as f:
|
||||
data = f.read()
|
||||
data = yaml.load(data, Loader=yaml.FullLoader)
|
||||
s1_dir = "%s/%s" % (exp_root, exp_name)
|
||||
os.makedirs("%s/logs_s1" % (s1_dir), exist_ok=True)
|
||||
s1_dir = f"{exp_root}/{exp_name}"
|
||||
os.makedirs(f"{s1_dir}/logs_s1", exist_ok=True)
|
||||
if check_for_existance([s1_dir], is_train=True):
|
||||
check_details([s1_dir], is_train=True)
|
||||
if is_half == False:
|
||||
@ -623,18 +699,18 @@ def open1Bb(
|
||||
data["train"]["if_dpo"] = if_dpo
|
||||
data["train"]["half_weights_save_dir"] = GPT_weight_version2root[version]
|
||||
data["train"]["exp_name"] = exp_name
|
||||
data["train_semantic_path"] = "%s/6-name2semantic.tsv" % s1_dir
|
||||
data["train_phoneme_path"] = "%s/2-name2text.txt" % s1_dir
|
||||
data["output_dir"] = "%s/logs_s1_%s" % (s1_dir, version)
|
||||
data["train_semantic_path"] = f"{s1_dir}/6-name2semantic.tsv"
|
||||
data["train_phoneme_path"] = f"{s1_dir}/2-name2text.txt"
|
||||
data["output_dir"] = f"{s1_dir}/logs_s1_{version}"
|
||||
# data["version"]=version
|
||||
|
||||
os.environ["_CUDA_VISIBLE_DEVICES"] = fix_gpu_numbers(gpu_numbers.replace("-", ","))
|
||||
os.environ["hz"] = "25hz"
|
||||
tmp_config_path = "%s/tmp_s1.yaml" % tmp
|
||||
tmp_config_path = f"{tmp}/tmp_s1.yaml"
|
||||
with open(tmp_config_path, "w") as f:
|
||||
f.write(yaml.dump(data, default_flow_style=False))
|
||||
# cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" --train_semantic_path "%s/6-name2semantic.tsv" --train_phoneme_path "%s/2-name2text.txt" --output_dir "%s/logs_s1"'%(python_exec,tmp_config_path,s1_dir,s1_dir,s1_dir)
|
||||
cmd = '"%s" -s GPT_SoVITS/s1_train.py --config_file "%s" ' % (python_exec, tmp_config_path)
|
||||
# cmd = f'"{python_exec}" GPT_SoVITS/s1_train.py --config_file "{tmp_config_path}" --train_semantic_path "{s1_dir}/6-name2semantic.tsv" --train_phoneme_path "{s1_dir}/2-name2text.txt" --output_dir "{s1_dir}/logs_s1"'
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/s1_train.py --config_file "{tmp_config_path}" '
|
||||
yield (
|
||||
process_info(process_name_gpt, "opened"),
|
||||
{"__type__": "update", "visible": False},
|
||||
@ -711,20 +787,7 @@ def open_slice(inp, opt_root, threshold, min_length, min_interval, hop_size, max
|
||||
return
|
||||
if ps_slice == []:
|
||||
for i_part in range(n_parts):
|
||||
cmd = '"%s" -s tools/slice_audio.py "%s" "%s" %s %s %s %s %s %s %s %s %s' % (
|
||||
python_exec,
|
||||
inp,
|
||||
opt_root,
|
||||
threshold,
|
||||
min_length,
|
||||
min_interval,
|
||||
hop_size,
|
||||
max_sil_kept,
|
||||
_max,
|
||||
alpha,
|
||||
i_part,
|
||||
n_parts,
|
||||
)
|
||||
cmd = f'"{python_exec}" -s tools/slice_audio.py "{inp}" "{opt_root}" {threshold} {min_length} {min_interval} {hop_size} {max_sil_kept} {_max} {alpha} {i_part} {n_parts}'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps_slice.append(p)
|
||||
@ -786,7 +849,7 @@ def open1a(inp_text, inp_wav_dir, exp_name, gpu_numbers, bert_pretrained_dir):
|
||||
check_details([inp_text, inp_wav_dir], is_dataset_processing=True)
|
||||
exp_name = exp_name.rstrip(" ")
|
||||
if ps1a == []:
|
||||
opt_dir = "%s/%s" % (exp_root, exp_name)
|
||||
opt_dir = f"{exp_root}/{exp_name}"
|
||||
config = {
|
||||
"inp_text": inp_text,
|
||||
"inp_wav_dir": inp_wav_dir,
|
||||
@ -806,7 +869,7 @@ def open1a(inp_text, inp_wav_dir, exp_name, gpu_numbers, bert_pretrained_dir):
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/1-get-text.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/1-get-text.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1a.append(p)
|
||||
@ -819,11 +882,11 @@ def open1a(inp_text, inp_wav_dir, exp_name, gpu_numbers, bert_pretrained_dir):
|
||||
p.wait()
|
||||
opt = []
|
||||
for i_part in range(all_parts):
|
||||
txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
|
||||
txt_path = f"{opt_dir}/2-name2text-{i_part}.txt"
|
||||
with open(txt_path, "r", encoding="utf8") as f:
|
||||
opt += f.read().strip("\n").split("\n")
|
||||
os.remove(txt_path)
|
||||
path_text = "%s/2-name2text.txt" % opt_dir
|
||||
path_text = f"{opt_dir}/2-name2text.txt"
|
||||
with open(path_text, "w", encoding="utf8") as f:
|
||||
f.write("\n".join(opt) + "\n")
|
||||
ps1a = []
|
||||
@ -880,7 +943,7 @@ def open1b(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained
|
||||
"inp_text": inp_text,
|
||||
"inp_wav_dir": inp_wav_dir,
|
||||
"exp_name": exp_name,
|
||||
"opt_dir": "%s/%s" % (exp_root, exp_name),
|
||||
"opt_dir": f"{exp_root}/{exp_name}",
|
||||
"cnhubert_base_dir": ssl_pretrained_dir,
|
||||
"sv_path": sv_path,
|
||||
"is_half": str(is_half),
|
||||
@ -896,7 +959,7 @@ def open1b(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1b.append(p)
|
||||
@ -918,7 +981,7 @@ def open1b(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-sv.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/2-get-sv.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1b.append(p)
|
||||
@ -965,7 +1028,7 @@ def open1c(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, pretrained_s2G
|
||||
check_details([inp_text, inp_wav_dir], is_dataset_processing=True)
|
||||
exp_name = exp_name.rstrip(" ")
|
||||
if ps1c == []:
|
||||
opt_dir = "%s/%s" % (exp_root, exp_name)
|
||||
opt_dir = f"{exp_root}/{exp_name}"
|
||||
config_file = (
|
||||
"GPT_SoVITS/configs/s2.json"
|
||||
if version not in {"v2Pro", "v2ProPlus"}
|
||||
@ -990,7 +1053,7 @@ def open1c(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, pretrained_s2G
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/3-get-semantic.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/3-get-semantic.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1c.append(p)
|
||||
@ -1002,9 +1065,9 @@ def open1c(version, inp_text, inp_wav_dir, exp_name, gpu_numbers, pretrained_s2G
|
||||
for p in ps1c:
|
||||
p.wait()
|
||||
opt = ["item_name\tsemantic_audio"]
|
||||
path_semantic = "%s/6-name2semantic.tsv" % opt_dir
|
||||
path_semantic = f"{opt_dir}/6-name2semantic.tsv"
|
||||
for i_part in range(all_parts):
|
||||
semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
|
||||
semantic_path = f"{opt_dir}/6-name2semantic-{i_part}.tsv"
|
||||
with open(semantic_path, "r", encoding="utf8") as f:
|
||||
opt += f.read().strip("\n").split("\n")
|
||||
os.remove(semantic_path)
|
||||
@ -1063,10 +1126,10 @@ def open1abc(
|
||||
check_details([inp_text, inp_wav_dir], is_dataset_processing=True)
|
||||
exp_name = exp_name.rstrip(" ")
|
||||
if ps1abc == []:
|
||||
opt_dir = "%s/%s" % (exp_root, exp_name)
|
||||
opt_dir = f"{exp_root}/{exp_name}"
|
||||
try:
|
||||
#############################1a
|
||||
path_text = "%s/2-name2text.txt" % opt_dir
|
||||
path_text = f"{opt_dir}/2-name2text.txt"
|
||||
if os.path.exists(path_text) == False or (
|
||||
os.path.exists(path_text) == True
|
||||
and len(open(path_text, "r", encoding="utf8").read().strip("\n").split("\n")) < 2
|
||||
@ -1090,7 +1153,7 @@ def open1abc(
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/1-get-text.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/1-get-text.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1abc.append(p)
|
||||
@ -1103,8 +1166,8 @@ def open1abc(
|
||||
p.wait()
|
||||
|
||||
opt = []
|
||||
for i_part in range(all_parts): # txt_path="%s/2-name2text-%s.txt"%(opt_dir,i_part)
|
||||
txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
|
||||
for i_part in range(all_parts): # txt_path=f"{opt_dir}/2-name2text-{i_part}.txt"
|
||||
txt_path = f"{opt_dir}/2-name2text-{i_part}.txt"
|
||||
with open(txt_path, "r", encoding="utf8") as f:
|
||||
opt += f.read().strip("\n").split("\n")
|
||||
os.remove(txt_path)
|
||||
@ -1137,7 +1200,7 @@ def open1abc(
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1abc.append(p)
|
||||
@ -1159,7 +1222,7 @@ def open1abc(
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-sv.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/2-get-sv.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1abc.append(p)
|
||||
@ -1172,7 +1235,7 @@ def open1abc(
|
||||
{"__type__": "update", "visible": True},
|
||||
)
|
||||
#############################1c
|
||||
path_semantic = "%s/6-name2semantic.tsv" % opt_dir
|
||||
path_semantic = f"{opt_dir}/6-name2semantic.tsv"
|
||||
if os.path.exists(path_semantic) == False or (
|
||||
os.path.exists(path_semantic) == True and os.path.getsize(path_semantic) < 31
|
||||
):
|
||||
@ -1199,7 +1262,7 @@ def open1abc(
|
||||
}
|
||||
)
|
||||
os.environ.update(config)
|
||||
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/3-get-semantic.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/prepare_datasets/3-get-semantic.py'
|
||||
print(cmd)
|
||||
p = Popen(cmd, shell=True)
|
||||
ps1abc.append(p)
|
||||
@ -1213,7 +1276,7 @@ def open1abc(
|
||||
|
||||
opt = ["item_name\tsemantic_audio"]
|
||||
for i_part in range(all_parts):
|
||||
semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
|
||||
semantic_path = f"{opt_dir}/6-name2semantic-{i_part}.tsv"
|
||||
with open(semantic_path, "r", encoding="utf8") as f:
|
||||
opt += f.read().strip("\n").split("\n")
|
||||
os.remove(semantic_path)
|
||||
@ -1294,7 +1357,7 @@ def switch_version(version_):
|
||||
if os.path.exists("GPT_SoVITS/text/G2PWModel"):
|
||||
...
|
||||
else:
|
||||
cmd = '"%s" -s GPT_SoVITS/download.py' % python_exec
|
||||
cmd = f'"{python_exec}" -s GPT_SoVITS/download.py'
|
||||
p = Popen(cmd, shell=True)
|
||||
p.wait()
|
||||
|
||||
@ -1553,7 +1616,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
|
||||
with gr.Row():
|
||||
gpu_numbers1a = gr.Textbox(
|
||||
label=i18n("GPU卡号以-分割,每个卡号一个进程"),
|
||||
value="%s-%s" % (gpus, gpus),
|
||||
value=f"{gpus}-{gpus}",
|
||||
interactive=True,
|
||||
)
|
||||
with gr.Row():
|
||||
@ -1578,7 +1641,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
|
||||
with gr.Row():
|
||||
gpu_numbers1Ba = gr.Textbox(
|
||||
label=i18n("GPU卡号以-分割,每个卡号一个进程"),
|
||||
value="%s-%s" % (gpus, gpus),
|
||||
value=f"{gpus}-{gpus}",
|
||||
interactive=True,
|
||||
)
|
||||
with gr.Row():
|
||||
@ -1603,7 +1666,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
|
||||
with gr.Row():
|
||||
gpu_numbers1c = gr.Textbox(
|
||||
label=i18n("GPU卡号以-分割,每个卡号一个进程"),
|
||||
value="%s-%s" % (gpus, gpus),
|
||||
value=f"{gpus}-{gpus}",
|
||||
interactive=True,
|
||||
)
|
||||
with gr.Row():
|
||||
@ -1770,7 +1833,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
|
||||
with gr.Row():
|
||||
gpu_numbers1Ba = gr.Textbox(
|
||||
label=i18n("GPU卡号以-分割,每个卡号一个进程"),
|
||||
value="%s" % (gpus),
|
||||
value=f"{gpus}",
|
||||
interactive=True,
|
||||
)
|
||||
with gr.Row():
|
||||
@ -1835,7 +1898,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
|
||||
with gr.Row():
|
||||
gpu_numbers1Bb = gr.Textbox(
|
||||
label=i18n("GPU卡号以-分割,每个卡号一个进程"),
|
||||
value="%s" % (gpus),
|
||||
value=f"{gpus}",
|
||||
interactive=True,
|
||||
)
|
||||
with gr.Row():
|
||||
|
Loading…
x
Reference in New Issue
Block a user