mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-07 19:40:44 +08:00
optimize(f0): move some f0s into rvc.f0
This commit is contained in:
@@ -89,7 +89,7 @@ class FeatureInput(object):
|
||||
self.model_rmvpe = RMVPE(
|
||||
"assets/rmvpe/rmvpe.pt", is_half=False, device="cpu"
|
||||
)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, threshold=0.03)
|
||||
return f0
|
||||
|
||||
def coarse_f0(self, f0):
|
||||
|
||||
@@ -52,7 +52,7 @@ class FeatureInput(object):
|
||||
self.model_rmvpe = RMVPE(
|
||||
"assets/rmvpe/rmvpe.pt", is_half=is_half, device="cuda"
|
||||
)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, threshold=0.03)
|
||||
return f0
|
||||
|
||||
def coarse_f0(self, f0):
|
||||
|
||||
@@ -50,7 +50,7 @@ class FeatureInput(object):
|
||||
self.model_rmvpe = RMVPE(
|
||||
"assets/rmvpe/rmvpe.pt", is_half=False, device=device
|
||||
)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, threshold=0.03)
|
||||
return f0
|
||||
|
||||
def coarse_f0(self, f0):
|
||||
|
||||
@@ -47,7 +47,7 @@ from torch.nn.parallel import DistributedDataParallel as DDP
|
||||
from torch.utils.data import DataLoader
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
|
||||
from rvc import utils
|
||||
from rvc.layers import utils
|
||||
from infer.lib.train.data_utils import (
|
||||
DistributedBucketSampler,
|
||||
TextAudioCollate,
|
||||
|
||||
@@ -5,40 +5,24 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from functools import lru_cache
|
||||
from time import time
|
||||
|
||||
import faiss
|
||||
import librosa
|
||||
import numpy as np
|
||||
import parselmouth
|
||||
import pyworld
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torchcrepe
|
||||
from scipy import signal
|
||||
|
||||
from rvc.f0 import PM, Harvest
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
|
||||
bh, ah = signal.butter(N=5, Wn=48, btype="high", fs=16000)
|
||||
|
||||
input_audio_path2wav = {}
|
||||
|
||||
|
||||
@lru_cache
|
||||
def cache_harvest_f0(f0_cache_key, fs, f0max, f0min, frame_period):
|
||||
audio = input_audio_path2wav[f0_cache_key]
|
||||
f0, t = pyworld.harvest(
|
||||
audio,
|
||||
fs=fs,
|
||||
f0_ceil=f0max,
|
||||
f0_floor=f0min,
|
||||
frame_period=frame_period,
|
||||
)
|
||||
f0 = pyworld.stonemask(audio, f0, t, fs)
|
||||
return f0
|
||||
|
||||
|
||||
def change_rms(data1, sr1, data2, sr2, rate): # 1是输入音频,2是输出音频,rate是2的占比
|
||||
# print(data1.max(),data2.max())
|
||||
@@ -90,37 +74,18 @@ class Pipeline(object):
|
||||
filter_radius,
|
||||
inp_f0=None,
|
||||
):
|
||||
global input_audio_path2wav
|
||||
time_step = self.window / self.sr * 1000
|
||||
f0_min = 50
|
||||
f0_max = 1100
|
||||
f0_mel_min = 1127 * np.log(1 + f0_min / 700)
|
||||
f0_mel_max = 1127 * np.log(1 + f0_max / 700)
|
||||
if f0_method == "pm":
|
||||
f0 = (
|
||||
parselmouth.Sound(x, self.sr)
|
||||
.to_pitch_ac(
|
||||
time_step=time_step / 1000,
|
||||
voicing_threshold=0.6,
|
||||
pitch_floor=f0_min,
|
||||
pitch_ceiling=f0_max,
|
||||
)
|
||||
.selected_array["frequency"]
|
||||
)
|
||||
pad_size = (p_len - len(f0) + 1) // 2
|
||||
if pad_size > 0 or p_len - len(f0) - pad_size > 0:
|
||||
f0 = np.pad(
|
||||
f0, [[pad_size, p_len - len(f0) - pad_size]], mode="constant"
|
||||
)
|
||||
if not hasattr(self, "pm"):
|
||||
self.pm = PM(self.window, f0_min, f0_max, self.sr)
|
||||
f0 = self.pm.compute_f0(x, p_len=p_len)
|
||||
elif f0_method == "harvest":
|
||||
from hashlib import md5
|
||||
|
||||
f0_cache_key = md5(x.tobytes()).digest()
|
||||
input_audio_path2wav[f0_cache_key] = x.astype(np.double)
|
||||
f0 = cache_harvest_f0(f0_cache_key, self.sr, f0_max, f0_min, 10)
|
||||
del input_audio_path2wav[f0_cache_key]
|
||||
if filter_radius > 2:
|
||||
f0 = signal.medfilt(f0, 3)
|
||||
if not hasattr(self, "harvest"):
|
||||
self.harvest = Harvest(self.window, f0_min, f0_max, self.sr)
|
||||
f0 = self.harvest.compute_f0(x, p_len=p_len, filter_radius=filter_radius)
|
||||
elif f0_method == "crepe":
|
||||
model = "full"
|
||||
# Pick a batch size that doesn't cause memory errors on your gpu
|
||||
@@ -155,7 +120,7 @@ class Pipeline(object):
|
||||
device=self.device,
|
||||
# use_jit=self.config.use_jit,
|
||||
)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
||||
f0 = self.model_rmvpe.infer_from_audio(x, threshold=0.03)
|
||||
|
||||
if "privateuseone" in str(self.device): # clean ortruntime memory
|
||||
del self.model_rmvpe.model
|
||||
|
||||
Reference in New Issue
Block a user