mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-06 01:30:24 +08:00
* feat(audio): use PyAV instead of ffmpeg replaced usage of ffmpeg in favor of PyAV (`av`) * refactor(audio): store all of the audio related functions in the `infer.lib.audio` refactors previous commit to have singular functions for each task, all located in `infer.lib.audio` * fix(audio): remove downsample_audio from mdxnet.py it is no longer needed, since it's imported from infer.lib.audio * docs: remove every ffmpeg mention in the documentation to avoid confusion * chore(requirements): remove ffmpeg-python and ffmpy from all requirements * fix(audio): fix loading for UVR wrapped gathering of META info from the stream into a function fixes loading for UVR * fix(audio): use np.frombuffer() instead of direct conversion of the resampled frames this fixes traceback on preprocessing * feat(audio): pre-allocate decoded_audio array in the load_audio function this should improve performance, even if just a little * Revert "docs: remove every ffmpeg mention in the documentation to avoid confusion" This reverts commit1e05bbce03. * chore(format): run black on dev * fix(requirements): revert removal of ffmpeg in unitest.yml and Dockerfile * Revert "fix(requirements): revert removal of ffmpeg in unitest.yml and Dockerfile" This reverts commite28a0eebb2. * feat(audio): pre-allocate numpy array to store the AudioFrame data in ndarray of dtype float32 * chore(format): run black on dev * fix(audio): fix the decoded_audio size estimation in estimated_total_samples we multiply by `sr` instead of `container.streams.audio[0].rate` since we want to estimate size of the OUTPUT file, not the input one. - Added dynamic resizing, in case something goes wrong and the size of decoded_audio is estimated incorrectly Fixed function `load_audio` when the input audio's samplerate does not match the desired samplerate (`sr`) * chore(format): run black on dev * refactor(audio): remove `clean_path()` function as it serves no purpose anymore * docs: remove everything related to ffmpeg this includes everything except for formats support specification in the training_tips docs, since it has nothing to do with what ffmpeg does/did but rather what audio formats are supported (all the ones that ffmpeg supports!) * docs: fix order of the steps in preparation in the READMEs --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
108 lines
3.9 KiB
Python
108 lines
3.9 KiB
Python
import os
|
|
import traceback
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
from infer.lib.audio import resample_audio, get_audio_properties
|
|
import torch
|
|
|
|
from configs import Config
|
|
from infer.modules.uvr5.mdxnet import MDXNetDereverb
|
|
from infer.modules.uvr5.vr import AudioPre, AudioPreDeEcho
|
|
|
|
config = Config()
|
|
|
|
|
|
def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format0):
|
|
infos = []
|
|
try:
|
|
inp_root = inp_root.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
|
save_root_vocal = (
|
|
save_root_vocal.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
|
)
|
|
save_root_ins = (
|
|
save_root_ins.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
|
)
|
|
if model_name == "onnx_dereverb_By_FoxJoy":
|
|
pre_fun = MDXNetDereverb(15, config.device)
|
|
else:
|
|
func = AudioPre if "DeEcho" not in model_name else AudioPreDeEcho
|
|
pre_fun = func(
|
|
agg=int(agg),
|
|
model_path=os.path.join(
|
|
os.getenv("weight_uvr5_root"), model_name + ".pth"
|
|
),
|
|
device=config.device,
|
|
is_half=config.is_half,
|
|
)
|
|
is_hp3 = "HP3" in model_name
|
|
if inp_root != "":
|
|
paths = [os.path.join(inp_root, name) for name in os.listdir(inp_root)]
|
|
else:
|
|
paths = [path.name for path in paths]
|
|
for path in paths:
|
|
inp_path = os.path.join(inp_root, path)
|
|
need_reformat = 1
|
|
done = 0
|
|
try:
|
|
channels, rate = get_audio_properties(inp_path)
|
|
|
|
# Check the audio stream's properties
|
|
if channels == 2 and rate == 44100:
|
|
pre_fun._path_audio_(
|
|
inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3
|
|
)
|
|
need_reformat = 0
|
|
done = 1
|
|
except Exception as e:
|
|
need_reformat = 1
|
|
print(f"Exception {e} occured. Will reformat")
|
|
if need_reformat == 1:
|
|
tmp_path = "%s/%s.reformatted.wav" % (
|
|
os.path.join(os.environ["TEMP"]),
|
|
os.path.basename(inp_path),
|
|
)
|
|
resample_audio(inp_path, tmp_path, "pcm_s16le", "s16", 44100, "stereo")
|
|
inp_path = tmp_path
|
|
try:
|
|
if done == 0:
|
|
pre_fun._path_audio_(
|
|
inp_path, save_root_ins, save_root_vocal, format0
|
|
)
|
|
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
|
yield "\n".join(infos)
|
|
except:
|
|
try:
|
|
if done == 0:
|
|
pre_fun._path_audio_(
|
|
inp_path, save_root_ins, save_root_vocal, format0
|
|
)
|
|
infos.append("%s->Success" % (os.path.basename(inp_path)))
|
|
yield "\n".join(infos)
|
|
except:
|
|
infos.append(
|
|
"%s->%s" % (os.path.basename(inp_path), traceback.format_exc())
|
|
)
|
|
yield "\n".join(infos)
|
|
except:
|
|
infos.append(traceback.format_exc())
|
|
yield "\n".join(infos)
|
|
finally:
|
|
try:
|
|
if model_name == "onnx_dereverb_By_FoxJoy":
|
|
del pre_fun.pred.model
|
|
del pre_fun.pred.model_
|
|
else:
|
|
del pre_fun.model
|
|
del pre_fun
|
|
except:
|
|
traceback.print_exc()
|
|
if torch.cuda.is_available():
|
|
torch.cuda.empty_cache()
|
|
logger.info("Executed torch.cuda.empty_cache()")
|
|
elif torch.backends.mps.is_available():
|
|
torch.mps.empty_cache()
|
|
logger.info("Executed torch.mps.empty_cache()")
|
|
yield "\n".join(infos)
|