Spaces:
Runtime error
Runtime error
File size: 1,392 Bytes
0047e35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import torch
from modules.F0Predictor.crepe import CrepePitchExtractor
from modules.F0Predictor.F0Predictor import F0Predictor
class CrepeF0Predictor(F0Predictor):
def __init__(self,hop_length=512,f0_min=50,f0_max=1100,device=None,sampling_rate=44100,threshold=0.05,model="full"):
self.F0Creper = CrepePitchExtractor(hop_length=hop_length,f0_min=f0_min,f0_max=f0_max,device=device,threshold=threshold,model=model)
self.hop_length = hop_length
self.f0_min = f0_min
self.f0_max = f0_max
self.device = device
self.threshold = threshold
self.sampling_rate = sampling_rate
self.name = "crepe"
def compute_f0(self,wav,p_len=None):
x = torch.FloatTensor(wav).to(self.device)
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"
f0,uv = self.F0Creper(x[None,:].float(),self.sampling_rate,pad_to=p_len)
return f0
def compute_f0_uv(self,wav,p_len=None):
x = torch.FloatTensor(wav).to(self.device)
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"
f0,uv = self.F0Creper(x[None,:].float(),self.sampling_rate,pad_to=p_len)
return f0,uv |