mirror of
https://github.com/w-okada/voice-changer.git
synced 2025-01-23 13:35:12 +03:00
WIP:crepe
This commit is contained in:
parent
8339e72ef5
commit
485a747d55
@ -11,30 +11,26 @@ class CrepePitchExtractor(PitchExtractor):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.pitchExtractorType: PitchExtractorType = "crepe"
|
||||
self.f0_min = 50
|
||||
self.f0_max = 1100
|
||||
self.sapmle_rate = 16000
|
||||
self.uv_interp = True
|
||||
if torch.cuda.is_available():
|
||||
self.device = torch.device("cuda:" + str(torch.cuda.current_device()))
|
||||
else:
|
||||
self.device = torch.device("cpu")
|
||||
|
||||
def extract(self, audio, pitchf, f0_up_key, sr, window, silence_front=0):
|
||||
n_frames = int(len(audio) // window) + 1
|
||||
start_frame = int(silence_front * sr / window)
|
||||
real_silence_front = start_frame * window / sr
|
||||
|
||||
silence_front_offset = int(np.round(real_silence_front * sr))
|
||||
audio = audio[silence_front_offset:]
|
||||
|
||||
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)
|
||||
def extract(self, audio: torch.Tensor, pitch, f0_up_key, window, silence_front=0):
|
||||
start_frame = int(silence_front * self.sapmle_rate / window)
|
||||
real_silence_front = start_frame * window / self.sapmle_rate
|
||||
audio = audio[int(np.round(real_silence_front * self.sapmle_rate)):]
|
||||
|
||||
f0, pd = torchcrepe.predict(
|
||||
audio.unsqueeze(0),
|
||||
sr,
|
||||
self.sapmle_rate,
|
||||
hop_length=window,
|
||||
fmin=f0_min,
|
||||
fmax=f0_max,
|
||||
fmin=self.f0_min,
|
||||
fmax=self.f0_max,
|
||||
# model="tiny",
|
||||
model="full",
|
||||
batch_size=256,
|
||||
@ -46,14 +42,15 @@ class CrepePitchExtractor(PitchExtractor):
|
||||
pd = torchcrepe.filter.median(pd, 3)
|
||||
f0[pd < 0.1] = 0
|
||||
f0 = f0.squeeze()
|
||||
pitch[-f0.shape[0]:] = f0.cpu()[:pitch.shape[0]]
|
||||
f0 = pitch
|
||||
|
||||
f0 *= pow(2, f0_up_key / 12)
|
||||
pitchf[-f0.shape[0]:] = f0.detach().cpu().numpy()[:pitchf.shape[0]]
|
||||
f0bak = pitchf.copy()
|
||||
f0_mel = 1127.0 * np.log(1.0 + f0bak / 700.0)
|
||||
f0_mel = np.clip(
|
||||
(f0_mel - f0_mel_min) * 254.0 / (f0_mel_max - f0_mel_min) + 1.0, 1.0, 255.0
|
||||
)
|
||||
pitch_coarse = f0_mel.astype(int)
|
||||
if self.uv_interp:
|
||||
uv = f0 == 0
|
||||
if len(f0[~uv]) > 0:
|
||||
f0[uv] = np.interp(np.where(uv)[0], np.where(~uv)[0], f0[~uv])
|
||||
f0[f0 < self.f0_min] = self.f0_min
|
||||
|
||||
return pitch_coarse, pitchf
|
||||
f0 = f0 * 2 ** (float(f0_up_key) / 12)
|
||||
|
||||
return f0
|
||||
|
@ -1,5 +1,6 @@
|
||||
from typing import Protocol
|
||||
from const import PitchExtractorType
|
||||
from voice_changer.DiffusionSVC.pitchExtractor.CrepePitchExtractor import CrepePitchExtractor
|
||||
from voice_changer.DiffusionSVC.pitchExtractor.DioPitchExtractor import DioPitchExtractor
|
||||
from voice_changer.DiffusionSVC.pitchExtractor.HarvestPitchExtractor import HarvestPitchExtractor
|
||||
from voice_changer.DiffusionSVC.pitchExtractor.PitchExtractor import PitchExtractor
|
||||
@ -29,8 +30,8 @@ class PitchExtractorManager(Protocol):
|
||||
return HarvestPitchExtractor()
|
||||
elif pitchExtractorType == "dio":
|
||||
return DioPitchExtractor()
|
||||
# elif pitchExtractorType == "crepe":
|
||||
# return CrepePitchExtractor()
|
||||
elif pitchExtractorType == "crepe":
|
||||
return CrepePitchExtractor()
|
||||
# elif pitchExtractorType == "crepe_tiny":
|
||||
# return CrepeOnnxPitchExtractor(pitchExtractorType, cls.params.crepe_onnx_tiny, gpu)
|
||||
# elif pitchExtractorType == "crepe_full":
|
||||
|
@ -2,6 +2,7 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
|
||||
class VolumeExtractor:
|
||||
|
||||
def __init__(self, hop_size: float):
|
||||
|
Loading…
Reference in New Issue
Block a user