1
0
mirror of https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git synced 2026-06-09 12:30:38 +08:00

feat(audio): use PyAV instead of ffmpeg (#31)

* 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 commit 1e05bbce03.

* 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 commit e28a0eebb2.

* 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>
This commit is contained in:
Alex Murkoff
2024-06-12 18:13:26 +07:00
committed by GitHub
parent aec56ec0b4
commit 1e22d468ea
28 changed files with 233 additions and 366 deletions

View File

@@ -6,6 +6,7 @@ logger = logging.getLogger(__name__)
import librosa
import numpy as np
import soundfile as sf
from infer.lib.audio import downsample_audio
import torch
from infer.lib.uvr5_pack.lib_v5 import nets_123821KB as Nets
@@ -60,7 +61,7 @@ class AudioPre:
(
X_wave[d],
_,
) = librosa.core.load( # 理论上librosa读取可能对某些音频有bug应该上ffmpeg读取,但是太麻烦了弃坑
) = librosa.core.load( # 理论上librosa读取可能对某些音频有bug应该上av读取,但是太麻烦了弃坑
music_file,
bp["sr"],
False,
@@ -146,12 +147,7 @@ class AudioPre:
)
if os.path.exists(path):
opt_format_path = path[:-4] + ".%s" % format
os.system(f'ffmpeg -i "{path}" -vn "{opt_format_path}" -q:a 2 -y')
if os.path.exists(opt_format_path):
try:
os.remove(path)
except:
pass
downsample_audio(path, opt_format_path, format)
if vocal_root is not None:
if is_hp3 == True:
head = "instrument_"
@@ -185,14 +181,8 @@ class AudioPre:
(np.array(wav_vocals) * 32768).astype("int16"),
self.mp.param["sr"],
)
if os.path.exists(path):
opt_format_path = path[:-4] + ".%s" % format
os.system(f'ffmpeg -i "{path}" -vn "{opt_format_path}" -q:a 2 -y')
if os.path.exists(opt_format_path):
try:
os.remove(path)
except:
pass
opt_format_path = path[:-4] + ".%s" % format
downsample_audio(path, opt_format_path, format)
class AudioPreDeEcho:
@@ -241,7 +231,7 @@ class AudioPreDeEcho:
(
X_wave[d],
_,
) = librosa.core.load( # 理论上librosa读取可能对某些音频有bug应该上ffmpeg读取,但是太麻烦了弃坑
) = librosa.core.load( # 理论上librosa读取可能对某些音频有bug应该上av读取,但是太麻烦了弃坑
music_file,
bp["sr"],
False,
@@ -323,12 +313,7 @@ class AudioPreDeEcho:
)
if os.path.exists(path):
opt_format_path = path[:-4] + ".%s" % format
os.system(f'ffmpeg -i "{path}" -vn "{opt_format_path}" -q:a 2 -y')
if os.path.exists(opt_format_path):
try:
os.remove(path)
except:
pass
downsample_audio(path, opt_format_path, format)
if vocal_root is not None:
if self.data["high_end_process"].startswith("mirroring"):
input_high_end_ = spec_utils.mirroring(
@@ -360,9 +345,4 @@ class AudioPreDeEcho:
)
if os.path.exists(path):
opt_format_path = path[:-4] + ".%s" % format
os.system(f'ffmpeg -i "{path}" -vn "{opt_format_path}" -q:a 2 -y')
if os.path.exists(opt_format_path):
try:
os.remove(path)
except:
pass
downsample_audio(path, opt_format_path, format)