mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-07 10:10:23 +08:00
optimize(crepe): move crepe into rvc.f0
This commit is contained in:
@@ -292,22 +292,16 @@ class RVC:
|
||||
self.device
|
||||
): ###不支持dml,cpu又太慢用不成,拿fcpe顶替
|
||||
return self.get_f0(x, f0_up_key, 1, "fcpe")
|
||||
# printt("using crepe,device:%s"%self.device)
|
||||
f0, pd = torchcrepe.predict(
|
||||
x.unsqueeze(0).float(),
|
||||
16000,
|
||||
160,
|
||||
self.f0_min,
|
||||
self.f0_max,
|
||||
"full",
|
||||
batch_size=512,
|
||||
# device=self.device if self.device.type!="privateuseone" else "cpu",###crepe不用半精度全部是全精度所以不愁###cpu延迟高到没法用
|
||||
device=self.device,
|
||||
return_periodicity=True,
|
||||
)
|
||||
pd = torchcrepe.filter.median(pd, 3)
|
||||
f0 = torchcrepe.filter.mean(f0, 3)
|
||||
f0[pd < 0.1] = 0
|
||||
if hasattr(self, "model_crepe") == False:
|
||||
from rvc.f0 import CRePE
|
||||
self.model_crepe = CRePE(
|
||||
160,
|
||||
self.f0_min,
|
||||
self.f0_max,
|
||||
16000,
|
||||
self.device,
|
||||
)
|
||||
f0 = self.model_crepe.compute_f0(x)
|
||||
f0 *= pow(2, f0_up_key / 12)
|
||||
return self.get_f0_post(f0)
|
||||
|
||||
|
||||
@@ -12,10 +12,9 @@ import librosa
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torchcrepe
|
||||
from scipy import signal
|
||||
|
||||
from rvc.f0 import PM, Harvest, RMVPE
|
||||
from rvc.f0 import PM, Harvest, RMVPE, CRePE, Dio
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
@@ -81,31 +80,24 @@ class Pipeline(object):
|
||||
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)
|
||||
if f0_method == "dio":
|
||||
if not hasattr(self, "dio"):
|
||||
self.dio = Dio(self.window, f0_min, f0_max, self.sr)
|
||||
f0 = self.dio.compute_f0(x, p_len=p_len)
|
||||
elif f0_method == "harvest":
|
||||
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
|
||||
batch_size = 512
|
||||
# Compute pitch using first gpu
|
||||
audio = torch.tensor(np.copy(x))[None].float()
|
||||
f0, pd = torchcrepe.predict(
|
||||
audio,
|
||||
self.sr,
|
||||
self.window,
|
||||
f0_min,
|
||||
f0_max,
|
||||
model,
|
||||
batch_size=batch_size,
|
||||
device=self.device,
|
||||
return_periodicity=True,
|
||||
)
|
||||
pd = torchcrepe.filter.median(pd, 3)
|
||||
f0 = torchcrepe.filter.mean(f0, 3)
|
||||
f0[pd < 0.1] = 0
|
||||
f0 = f0[0].cpu().numpy()
|
||||
if not hasattr(self, "crepe"):
|
||||
self.crepe = CRePE(
|
||||
self.window,
|
||||
f0_min,
|
||||
f0_max,
|
||||
self.sr,
|
||||
self.device,
|
||||
)
|
||||
f0 = self.crepe.compute_f0(x, p_len=p_len)
|
||||
elif f0_method == "rmvpe":
|
||||
if not hasattr(self, "rmvpe"):
|
||||
logger.info(
|
||||
@@ -117,7 +109,7 @@ class Pipeline(object):
|
||||
device=self.device,
|
||||
# use_jit=self.config.use_jit,
|
||||
)
|
||||
f0 = self.rmvpe.compute_f0(x, filter_radius=0.03)
|
||||
f0 = self.rmvpe.compute_f0(x, p_len=p_len, filter_radius=0.03)
|
||||
|
||||
if "privateuseone" in str(self.device): # clean ortruntime memory
|
||||
del self.rmvpe.model
|
||||
|
||||
Reference in New Issue
Block a user