mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-08-29 10:09:32 +02:00
Use GPU processing for UVR5 and input audio loading and resampling where possible to improve inference efficiency and reduce CPU usage
This commit is contained in:
@@ -8,9 +8,8 @@ import logging
|
||||
|
||||
import numpy as np
|
||||
|
||||
from infer.audio import load_audio
|
||||
from i18n.i18n import I18nAuto
|
||||
from tools.progress import should_report
|
||||
from i18n.i18n import I18nAuto
|
||||
from tools.progress import should_report
|
||||
|
||||
|
||||
i18n = I18nAuto()
|
||||
@@ -44,6 +43,9 @@ elif mode in ("dml", "directml"):
|
||||
else:
|
||||
raise ValueError("Unsupported F0 extraction mode: %s" % mode)
|
||||
|
||||
# CUDA_VISIBLE_DEVICES must be set before infer.audio imports torch/configs.
|
||||
from infer.audio import load_audio
|
||||
|
||||
f = open("%s/extract_f0_feature.log" % exp_dir, "a", encoding="utf8")
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import numpy as np
|
||||
import numpy as np
|
||||
|
||||
|
||||
# This function is obtained from librosa.
|
||||
def get_rms(
|
||||
def get_rms(
|
||||
y,
|
||||
frame_length=2048,
|
||||
hop_length=512,
|
||||
pad_mode="constant",
|
||||
):
|
||||
padding = (int(frame_length // 2), int(frame_length // 2))
|
||||
y = np.pad(y, padding, mode=pad_mode)
|
||||
):
|
||||
padding = (int(frame_length // 2), int(frame_length // 2))
|
||||
y = np.pad(y, padding, mode=pad_mode)
|
||||
|
||||
axis = -1
|
||||
# put our new within-frame axis at the end for now
|
||||
@@ -72,16 +72,16 @@ class Slicer:
|
||||
]
|
||||
|
||||
# @timeit
|
||||
def slice(self, waveform):
|
||||
if len(waveform.shape) > 1:
|
||||
samples = waveform.mean(axis=0)
|
||||
else:
|
||||
samples = waveform
|
||||
def slice(self, waveform):
|
||||
if len(waveform.shape) > 1:
|
||||
samples = waveform.mean(axis=0)
|
||||
else:
|
||||
samples = waveform
|
||||
if samples.shape[0] <= self.min_length:
|
||||
return [waveform]
|
||||
rms_list = get_rms(
|
||||
y=samples, frame_length=self.win_size, hop_length=self.hop_size
|
||||
).squeeze(0)
|
||||
rms_list = get_rms(
|
||||
y=samples, frame_length=self.win_size, hop_length=self.hop_size
|
||||
).squeeze(0)
|
||||
sil_tags = []
|
||||
silence_start = None
|
||||
clip_start = 0
|
||||
|
||||
@@ -10,13 +10,13 @@ n_p = int(sys.argv[3])
|
||||
exp_dir = sys.argv[4]
|
||||
noparallel = sys.argv[5] == "True"
|
||||
per = float(sys.argv[6])
|
||||
import os
|
||||
import traceback
|
||||
|
||||
import librosa
|
||||
import numpy as np
|
||||
from scipy.io import wavfile
|
||||
|
||||
os.environ["RVC_AUDIO_FORCE_CPU"] = "1"
|
||||
from infer.audio import load_audio
|
||||
from train.dataset.slicer2 import Slicer
|
||||
from i18n.i18n import I18nAuto
|
||||
@@ -73,13 +73,13 @@ class PreProcess:
|
||||
self.sr,
|
||||
tmp_audio.astype(np.float32),
|
||||
)
|
||||
tmp_audio = librosa.resample(
|
||||
audio_16k = librosa.resample(
|
||||
tmp_audio, orig_sr=self.sr, target_sr=16000
|
||||
) # , res_type="soxr_vhq"
|
||||
).astype(np.float32)
|
||||
wavfile.write(
|
||||
"%s/%s_%s.wav" % (self.wavs16k_dir, idx0, idx1),
|
||||
16000,
|
||||
tmp_audio.astype(np.float32),
|
||||
audio_16k,
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -140,19 +140,24 @@ class PreProcess:
|
||||
("%s/%s" % (inp_root, name), idx, total)
|
||||
for idx, name in enumerate(names)
|
||||
]
|
||||
println(i18n("[数据切分] 待处理:%s | 进程数:%s") % (total, n_p))
|
||||
worker_count = max(n_p, 1)
|
||||
worker_count = min(worker_count, max(total, 1))
|
||||
println(
|
||||
i18n("[数据切分] 待处理:%s | 进程数:%s")
|
||||
% (total, worker_count)
|
||||
)
|
||||
if noparallel:
|
||||
for i in range(n_p):
|
||||
self.pipeline_mp(infos[i::n_p])
|
||||
for i in range(worker_count):
|
||||
self.pipeline_mp(infos[i::worker_count])
|
||||
else:
|
||||
ps = []
|
||||
for i in range(n_p):
|
||||
for i in range(worker_count):
|
||||
p = multiprocessing.Process(
|
||||
target=self.pipeline_mp, args=(infos[i::n_p],)
|
||||
target=self.pipeline_mp, args=(infos[i::worker_count],)
|
||||
)
|
||||
ps.append(p)
|
||||
p.start()
|
||||
for i in range(n_p):
|
||||
for i in range(worker_count):
|
||||
ps[i].join()
|
||||
except Exception:
|
||||
println(i18n("[数据切分][失败] %s") % traceback.format_exc())
|
||||
|
||||
Reference in New Issue
Block a user