mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-05 01:10:22 +08:00
chore(format): run black on dev (#3)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6e8feb9028
commit
c94f3f6748
@@ -9,7 +9,9 @@ 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):
|
||||
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(
|
||||
@@ -24,7 +26,9 @@ class DioF0Predictor(F0Predictor):
|
||||
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):
|
||||
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(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
import typing
|
||||
|
||||
|
||||
class F0Predictor(object):
|
||||
def __init__(self, hop_length=512, f0_min=50, f0_max=1100, sampling_rate=44100):
|
||||
self.hop_length = hop_length
|
||||
@@ -8,9 +9,13 @@ class F0Predictor(object):
|
||||
self.f0_max = f0_max
|
||||
self.sampling_rate = sampling_rate
|
||||
|
||||
def compute_f0(self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None): ...
|
||||
def compute_f0(
|
||||
self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None
|
||||
): ...
|
||||
|
||||
def compute_f0_uv(self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None): ...
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None
|
||||
): ...
|
||||
|
||||
def __interpolate_f0(self, f0: np.ndarray[typing.Any, np.dtype]):
|
||||
"""
|
||||
@@ -49,7 +54,7 @@ class F0Predictor(object):
|
||||
last_value = data[i]
|
||||
|
||||
return ip_data[:, 0], vuv_vector[:, 0]
|
||||
|
||||
|
||||
def __resize_f0(self, x: np.ndarray[typing.Any, np.dtype], target_len: int):
|
||||
source = np.array(x)
|
||||
source[source < 0.001] = np.nan
|
||||
|
||||
@@ -9,7 +9,9 @@ class HarvestF0Predictor(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):
|
||||
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.harvest(
|
||||
@@ -22,7 +24,9 @@ class HarvestF0Predictor(F0Predictor):
|
||||
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[typing.Any, np.dtype], p_len: int | None = None):
|
||||
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.harvest(
|
||||
|
||||
@@ -9,7 +9,9 @@ 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[typing.Any, np.dtype], p_len: int | None = None):
|
||||
def compute_f0(
|
||||
self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None
|
||||
):
|
||||
x = wav
|
||||
if p_len is None:
|
||||
p_len = x.shape[0] // self.hop_length
|
||||
@@ -33,7 +35,9 @@ class PMF0Predictor(F0Predictor):
|
||||
f0, uv = self.__interpolate_f0(f0)
|
||||
return f0
|
||||
|
||||
def compute_f0_uv(self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None):
|
||||
def compute_f0_uv(
|
||||
self, wav: np.ndarray[typing.Any, np.dtype], p_len: int | None = None
|
||||
):
|
||||
x = wav
|
||||
if p_len is None:
|
||||
p_len = x.shape[0] // self.hop_length
|
||||
|
||||
@@ -4,11 +4,20 @@ import onnxruntime
|
||||
import typing
|
||||
import os
|
||||
|
||||
from onnx.f0predictor import PMF0Predictor, HarvestF0Predictor, DioF0Predictor, F0Predictor
|
||||
from onnx.f0predictor import (
|
||||
PMF0Predictor,
|
||||
HarvestF0Predictor,
|
||||
DioF0Predictor,
|
||||
F0Predictor,
|
||||
)
|
||||
|
||||
|
||||
class Model:
|
||||
def __init__(self, path: str | bytes | os.PathLike, device: typing.Literal["cpu", "cuda", "dml"]="cpu"):
|
||||
def __init__(
|
||||
self,
|
||||
path: str | bytes | os.PathLike,
|
||||
device: typing.Literal["cpu", "cuda", "dml"] = "cpu",
|
||||
):
|
||||
if device == "cpu":
|
||||
providers = ["CPUExecutionProvider"]
|
||||
elif device == "cuda":
|
||||
@@ -19,8 +28,13 @@ class Model:
|
||||
raise RuntimeError("Unsportted Device")
|
||||
self.model = onnxruntime.InferenceSession(path, providers=providers)
|
||||
|
||||
|
||||
class ContentVec(Model):
|
||||
def __init__(self, vec_path: str | bytes | os.PathLike, device: typing.Literal["cpu", "cuda", "dml"]="cpu"):
|
||||
def __init__(
|
||||
self,
|
||||
vec_path: str | bytes | os.PathLike,
|
||||
device: typing.Literal["cpu", "cuda", "dml"] = "cpu",
|
||||
):
|
||||
super().__init__(vec_path, device)
|
||||
|
||||
def __call__(self, wav: np.ndarray[typing.Any, np.dtype]):
|
||||
@@ -43,7 +57,9 @@ predictors: typing.Dict[str, F0Predictor] = {
|
||||
}
|
||||
|
||||
|
||||
def get_f0_predictor(f0_method: str, hop_length: int, sampling_rate: int) -> F0Predictor:
|
||||
def get_f0_predictor(
|
||||
f0_method: str, hop_length: int, sampling_rate: int
|
||||
) -> F0Predictor:
|
||||
return predictors[f0_method](hop_length=hop_length, sampling_rate=sampling_rate)
|
||||
|
||||
|
||||
@@ -107,7 +123,9 @@ class RVC(Model):
|
||||
rnd = np.random.randn(1, 192, hubert_length).astype(np.float32)
|
||||
hubert_length = np.array([hubert_length]).astype(np.int64)
|
||||
|
||||
out_wav = self.__forward(hubert, hubert_length, pitch, pitchf, ds, rnd).squeeze()
|
||||
out_wav = self.__forward(
|
||||
hubert, hubert_length, pitch, pitchf, ds, rnd
|
||||
).squeeze()
|
||||
out_wav = np.pad(out_wav, (0, 2 * self.hop_size), "constant")
|
||||
return out_wav[0:org_length]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user