mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-06 09:40:24 +08:00
chore(format): run black on dev (#94)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a8783c6639
commit
d3add81469
@@ -62,15 +62,24 @@ class PreProcess:
|
||||
tmp_audio = (tmp_audio / tmp_max * (self.max * self.alpha)) + (
|
||||
1 - self.alpha
|
||||
) * tmp_audio
|
||||
save_audio("%s/%s_%s.wav" % (self.gt_wavs_dir, idx0, idx1), tmp_audio, self.sr, f32=True)
|
||||
save_audio(
|
||||
"%s/%s_%s.wav" % (self.gt_wavs_dir, idx0, idx1),
|
||||
tmp_audio,
|
||||
self.sr,
|
||||
f32=True,
|
||||
)
|
||||
with open("%s/%s_%s.wav" % (self.wavs16k_dir, idx0, idx1), "wb") as f:
|
||||
f.write(float_np_array_to_wav_buf(
|
||||
load_audio(
|
||||
float_np_array_to_wav_buf(tmp_audio, self.sr, f32=True),
|
||||
sr=16000,
|
||||
format="wav",
|
||||
)
|
||||
, 16000, True).getbuffer())
|
||||
f.write(
|
||||
float_np_array_to_wav_buf(
|
||||
load_audio(
|
||||
float_np_array_to_wav_buf(tmp_audio, self.sr, f32=True),
|
||||
sr=16000,
|
||||
format="wav",
|
||||
),
|
||||
16000,
|
||||
True,
|
||||
).getbuffer()
|
||||
)
|
||||
|
||||
def pipeline(self, path, idx0):
|
||||
try:
|
||||
|
||||
@@ -133,11 +133,21 @@ def run(rank, n_gpus, hps: utils.HParams, logger: logging.Logger):
|
||||
|
||||
try:
|
||||
dist.init_process_group(
|
||||
backend="gloo" if os.name == "nt" or not torch.cuda.is_available() else "nccl", init_method="env://", world_size=n_gpus, rank=rank
|
||||
backend=(
|
||||
"gloo" if os.name == "nt" or not torch.cuda.is_available() else "nccl"
|
||||
),
|
||||
init_method="env://",
|
||||
world_size=n_gpus,
|
||||
rank=rank,
|
||||
)
|
||||
except:
|
||||
dist.init_process_group(
|
||||
backend="gloo" if os.name == "nt" or not torch.cuda.is_available() else "nccl", init_method="env://?use_libuv=False", world_size=n_gpus, rank=rank
|
||||
backend=(
|
||||
"gloo" if os.name == "nt" or not torch.cuda.is_available() else "nccl"
|
||||
),
|
||||
init_method="env://?use_libuv=False",
|
||||
world_size=n_gpus,
|
||||
rank=rank,
|
||||
)
|
||||
torch.manual_seed(hps.train.seed)
|
||||
if torch.cuda.is_available():
|
||||
@@ -243,13 +253,17 @@ def run(rank, n_gpus, hps: utils.HParams, logger: logging.Logger):
|
||||
if hasattr(net_g, "module"):
|
||||
logger.info(
|
||||
net_g.module.load_state_dict(
|
||||
torch.load(hps.pretrainG, map_location="cpu", weights_only=True)["model"]
|
||||
torch.load(
|
||||
hps.pretrainG, map_location="cpu", weights_only=True
|
||||
)["model"]
|
||||
)
|
||||
) ##测试不加载优化器
|
||||
else:
|
||||
logger.info(
|
||||
net_g.load_state_dict(
|
||||
torch.load(hps.pretrainG, map_location="cpu", weights_only=True)["model"]
|
||||
torch.load(
|
||||
hps.pretrainG, map_location="cpu", weights_only=True
|
||||
)["model"]
|
||||
)
|
||||
) ##测试不加载优化器
|
||||
if hps.pretrainD != "":
|
||||
@@ -258,13 +272,17 @@ def run(rank, n_gpus, hps: utils.HParams, logger: logging.Logger):
|
||||
if hasattr(net_d, "module"):
|
||||
logger.info(
|
||||
net_d.module.load_state_dict(
|
||||
torch.load(hps.pretrainD, map_location="cpu", weights_only=True)["model"]
|
||||
torch.load(
|
||||
hps.pretrainD, map_location="cpu", weights_only=True
|
||||
)["model"]
|
||||
)
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
net_d.load_state_dict(
|
||||
torch.load(hps.pretrainD, map_location="cpu", weights_only=True)["model"]
|
||||
torch.load(
|
||||
hps.pretrainD, map_location="cpu", weights_only=True
|
||||
)["model"]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -208,8 +208,12 @@ class Predictor:
|
||||
sources = self.demix(mix.T)
|
||||
opt = sources[0].T
|
||||
if format in ["wav", "flac"]:
|
||||
save_audio("%s/vocal_%s.%s" % (vocal_root, basename, format), mix - opt, rate)
|
||||
save_audio("%s/instrument_%s.%s" % (others_root, basename, format), opt, rate)
|
||||
save_audio(
|
||||
"%s/vocal_%s.%s" % (vocal_root, basename, format), mix - opt, rate
|
||||
)
|
||||
save_audio(
|
||||
"%s/instrument_%s.%s" % (others_root, basename, format), opt, rate
|
||||
)
|
||||
else:
|
||||
path_vocal = "%s/vocal_%s.wav" % (vocal_root, basename)
|
||||
path_other = "%s/instrument_%s.wav" % (others_root, basename)
|
||||
|
||||
@@ -48,9 +48,7 @@ class AudioPre:
|
||||
self.mp = mp
|
||||
self.model = model
|
||||
|
||||
def _path_audio_(
|
||||
self, music_file, ins_root=None, vocal_root=None, format="flac"
|
||||
):
|
||||
def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac"):
|
||||
if ins_root is None and vocal_root is None:
|
||||
return "No save root."
|
||||
name = os.path.basename(music_file)
|
||||
@@ -134,10 +132,14 @@ class AudioPre:
|
||||
else:
|
||||
head = "instrument_"
|
||||
if format in ["wav", "flac"]:
|
||||
save_audio(os.path.join(
|
||||
save_audio(
|
||||
os.path.join(
|
||||
ins_root,
|
||||
head + "{}_{}.{}".format(name, self.data["agg"], format),
|
||||
), wav_instrument, self.mp.param["sr"])
|
||||
),
|
||||
wav_instrument,
|
||||
self.mp.param["sr"],
|
||||
)
|
||||
else:
|
||||
path = os.path.join(
|
||||
ins_root, head + "{}_{}.wav".format(name, self.data["agg"])
|
||||
@@ -162,10 +164,14 @@ class AudioPre:
|
||||
wav_vocals = spec_utils.cmb_spectrogram_to_wave(v_spec_m, self.mp)
|
||||
logger.info("%s vocals done" % name)
|
||||
if format in ["wav", "flac"]:
|
||||
save_audio(os.path.join(
|
||||
save_audio(
|
||||
os.path.join(
|
||||
vocal_root,
|
||||
head + "{}_{}.{}".format(name, self.data["agg"], format),
|
||||
), wav_vocals, self.mp.param["sr"])
|
||||
),
|
||||
wav_vocals,
|
||||
self.mp.param["sr"],
|
||||
)
|
||||
else:
|
||||
path = os.path.join(
|
||||
vocal_root, head + "{}_{}.wav".format(name, self.data["agg"])
|
||||
|
||||
@@ -252,8 +252,12 @@ class VC:
|
||||
try:
|
||||
tgt_sr, audio_opt = opt
|
||||
if format1 in ["wav", "flac"]:
|
||||
save_audio("%s/%s.%s"
|
||||
% (opt_root, os.path.basename(path), format1), audio_opt, tgt_sr)
|
||||
save_audio(
|
||||
"%s/%s.%s"
|
||||
% (opt_root, os.path.basename(path), format1),
|
||||
audio_opt,
|
||||
tgt_sr,
|
||||
)
|
||||
else:
|
||||
path = "%s/%s.%s" % (
|
||||
opt_root,
|
||||
@@ -261,7 +265,11 @@ class VC:
|
||||
format1,
|
||||
)
|
||||
with open(path, "wb") as outf:
|
||||
wav2(float_np_array_to_wav_buf(audio_opt, tgt_sr), outf, format1)
|
||||
wav2(
|
||||
float_np_array_to_wav_buf(audio_opt, tgt_sr),
|
||||
outf,
|
||||
format1,
|
||||
)
|
||||
except:
|
||||
info += traceback.format_exc()
|
||||
infos.append("%s->%s" % (os.path.basename(path), info))
|
||||
|
||||
Reference in New Issue
Block a user