mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-09 04:29:50 +08:00
optimize(f0): move some f0s into rvc.f0
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
from .dio import Dio
|
||||
from .harvest import Harvest
|
||||
from .pm import PM
|
||||
from .f0 import F0Predictor
|
||||
|
||||
@@ -6,27 +6,15 @@ import pyworld
|
||||
from .f0 import F0Predictor
|
||||
|
||||
|
||||
class DioF0Predictor(F0Predictor):
|
||||
class Dio(F0Predictor):
|
||||
def __init__(self, hop_length=512, f0_min=50, f0_max=1100, sampling_rate=44100):
|
||||
super().__init__(hop_length, f0_min, f0_max, sampling_rate)
|
||||
|
||||
def compute_f0(self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None):
|
||||
if p_len is None:
|
||||
p_len = wav.shape[0] // self.hop_length
|
||||
f0, t = pyworld.dio(
|
||||
wav.astype(np.double),
|
||||
fs=self.sampling_rate,
|
||||
f0_floor=self.f0_min,
|
||||
f0_ceil=self.f0_max,
|
||||
frame_period=1000 * self.hop_length / self.sampling_rate,
|
||||
)
|
||||
f0 = pyworld.stonemask(wav.astype(np.double), f0, t, self.sampling_rate)
|
||||
for index, pitch in enumerate(f0):
|
||||
f0[index] = round(pitch, 1)
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))[0]
|
||||
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None
|
||||
def compute_f0(
|
||||
self,
|
||||
wav: np.ndarray[Any, np.dtype],
|
||||
p_len: Optional[int] = None,
|
||||
filter_radius: Optional[int] = None,
|
||||
):
|
||||
if p_len is None:
|
||||
p_len = wav.shape[0] // self.hop_length
|
||||
@@ -40,4 +28,4 @@ class DioF0Predictor(F0Predictor):
|
||||
f0 = pyworld.stonemask(wav.astype(np.double), f0, t, self.sampling_rate)
|
||||
for index, pitch in enumerate(f0):
|
||||
f0[index] = round(pitch, 1)
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))[0]
|
||||
@@ -11,11 +11,10 @@ class F0Predictor(object):
|
||||
self.sampling_rate = sampling_rate
|
||||
|
||||
def compute_f0(
|
||||
self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None
|
||||
): ...
|
||||
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None
|
||||
self,
|
||||
wav: np.ndarray[Any, np.dtype],
|
||||
p_len: Optional[int] = None,
|
||||
filter_radius: Optional[int] = None,
|
||||
): ...
|
||||
|
||||
def interpolate_f0(self, f0: np.ndarray[Any, np.dtype]):
|
||||
@@ -2,38 +2,31 @@ from typing import Any, Optional
|
||||
|
||||
import numpy as np
|
||||
import pyworld
|
||||
from scipy import signal
|
||||
|
||||
from .f0 import F0Predictor
|
||||
|
||||
|
||||
class HarvestF0Predictor(F0Predictor):
|
||||
class Harvest(F0Predictor):
|
||||
def __init__(self, hop_length=512, f0_min=50, f0_max=1100, sampling_rate=44100):
|
||||
super().__init__(hop_length, f0_min, f0_max, sampling_rate)
|
||||
|
||||
def compute_f0(self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None):
|
||||
if p_len is None:
|
||||
p_len = wav.shape[0] // self.hop_length
|
||||
f0, t = pyworld.harvest(
|
||||
wav.astype(np.double),
|
||||
fs=self.sampling_rate,
|
||||
f0_ceil=self.f0_max,
|
||||
f0_floor=self.f0_min,
|
||||
frame_period=1000 * self.hop_length / self.sampling_rate,
|
||||
)
|
||||
f0 = pyworld.stonemask(wav.astype(np.double), f0, t, self.fs)
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))[0]
|
||||
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None
|
||||
def compute_f0(
|
||||
self,
|
||||
wav: np.ndarray[Any, np.dtype],
|
||||
p_len: Optional[int] = None,
|
||||
filter_radius: Optional[int] = None,
|
||||
):
|
||||
if p_len is None:
|
||||
p_len = wav.shape[0] // self.hop_length
|
||||
f0, t = pyworld.harvest(
|
||||
wav.astype(np.double),
|
||||
fs=self.sampling_rate,
|
||||
f0_floor=self.f0_min,
|
||||
f0_ceil=self.f0_max,
|
||||
f0_floor=self.f0_min,
|
||||
frame_period=1000 * self.hop_length / self.sampling_rate,
|
||||
)
|
||||
f0 = pyworld.stonemask(wav.astype(np.double), f0, t, self.sampling_rate)
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))
|
||||
if filter_radius is not None and filter_radius > 2:
|
||||
f0 = signal.medfilt(f0, 3)
|
||||
return self.interpolate_f0(self.resize_f0(f0, p_len))[0]
|
||||
39
rvc/f0/pm.py
Normal file
39
rvc/f0/pm.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
import numpy as np
|
||||
import parselmouth
|
||||
|
||||
from .f0 import F0Predictor
|
||||
|
||||
|
||||
class PM(F0Predictor):
|
||||
def __init__(self, hop_length=512, f0_min=50, f0_max=1100, sampling_rate=44100):
|
||||
super().__init__(hop_length, f0_min, f0_max, sampling_rate)
|
||||
|
||||
def compute_f0(
|
||||
self,
|
||||
wav: np.ndarray[Any, np.dtype],
|
||||
p_len: Optional[int] = None,
|
||||
filter_radius: Optional[int] = None,
|
||||
):
|
||||
x = wav
|
||||
if p_len is None:
|
||||
p_len = x.shape[0] // self.hop_length
|
||||
else:
|
||||
assert abs(p_len - x.shape[0] // self.hop_length) < 4, "pad length error"
|
||||
time_step = self.hop_length / self.sampling_rate * 1000
|
||||
f0 = (
|
||||
parselmouth.Sound(x, self.sampling_rate)
|
||||
.to_pitch_ac(
|
||||
time_step=time_step / 1000,
|
||||
voicing_threshold=0.6,
|
||||
pitch_floor=self.f0_min,
|
||||
pitch_ceiling=self.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")
|
||||
return self.interpolate_f0(f0)[0]
|
||||
@@ -1,4 +0,0 @@
|
||||
from .dio import DioF0Predictor
|
||||
from .harvest import HarvestF0Predictor
|
||||
from .pm import PMF0Predictor
|
||||
from .f0 import F0Predictor
|
||||
@@ -1,61 +0,0 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
import numpy as np
|
||||
import parselmouth
|
||||
|
||||
from .f0 import F0Predictor
|
||||
|
||||
|
||||
class PMF0Predictor(F0Predictor):
|
||||
def __init__(self, hop_length=512, f0_min=50, f0_max=1100, sampling_rate=44100):
|
||||
super().__init__(hop_length, f0_min, f0_max, sampling_rate)
|
||||
|
||||
def compute_f0(self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None):
|
||||
x = wav
|
||||
if p_len is None:
|
||||
p_len = x.shape[0] // self.hop_length
|
||||
else:
|
||||
assert abs(p_len - x.shape[0] // self.hop_length) < 4, "pad length error"
|
||||
time_step = self.hop_length / self.sampling_rate * 1000
|
||||
f0 = (
|
||||
parselmouth.Sound(x, self.sampling_rate)
|
||||
.to_pitch_ac(
|
||||
time_step=time_step / 1000,
|
||||
voicing_threshold=0.6,
|
||||
pitch_floor=self.f0_min,
|
||||
pitch_ceiling=self.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")
|
||||
f0, uv = self.interpolate_f0(f0)
|
||||
return f0
|
||||
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[Any, np.dtype], p_len: Optional[int] = None
|
||||
):
|
||||
x = wav
|
||||
if p_len is None:
|
||||
p_len = x.shape[0] // self.hop_length
|
||||
else:
|
||||
assert abs(p_len - x.shape[0] // self.hop_length) < 4, "pad length error"
|
||||
time_step = self.hop_length / self.sampling_rate * 1000
|
||||
f0 = (
|
||||
parselmouth.Sound(x, self.sampling_rate)
|
||||
.to_pitch_ac(
|
||||
time_step=time_step / 1000,
|
||||
voicing_threshold=0.6,
|
||||
pitch_floor=self.f0_min,
|
||||
pitch_ceiling=self.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")
|
||||
f0, uv = self.interpolate_f0(f0)
|
||||
return f0, uv
|
||||
@@ -5,10 +5,10 @@ import librosa
|
||||
import numpy as np
|
||||
import onnxruntime
|
||||
|
||||
from .f0 import (
|
||||
PMF0Predictor,
|
||||
HarvestF0Predictor,
|
||||
DioF0Predictor,
|
||||
from rvc.f0 import (
|
||||
PM,
|
||||
Harvest,
|
||||
Dio,
|
||||
F0Predictor,
|
||||
)
|
||||
|
||||
@@ -52,9 +52,9 @@ class ContentVec(Model):
|
||||
|
||||
|
||||
predictors: typing.Dict[str, F0Predictor] = {
|
||||
"pm": PMF0Predictor,
|
||||
"harvest": HarvestF0Predictor,
|
||||
"dio": DioF0Predictor,
|
||||
"pm": PM,
|
||||
"harvest": Harvest,
|
||||
"dio": Dio,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user