1
0
mirror of https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git synced 2026-06-10 21:24:16 +08:00

optimize(infer): move attentions into rvc

This commit is contained in:
源文雨
2024-06-07 20:28:05 +09:00
parent 978abd8aac
commit 96604e8175
12 changed files with 195 additions and 341 deletions

View File

@@ -0,0 +1,44 @@
import numpy as np
import pyworld
import typing
from .f0 import F0Predictor
class DioF0Predictor(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[typing.Any, np.dtype], p_len: int | None = 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[typing.Any, np.dtype], p_len: int | None = 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))