fixed audio

This commit is contained in:
SayanoAI
2024-10-06 21:39:08 -04:00
parent 1f05cf1fff
commit 69e8d01634
6 changed files with 43 additions and 41 deletions
+12 -5
View File
@@ -50,21 +50,24 @@ class AudioProcessor:
return get_hash(*values)
def __call__(self, audio):
from .karafan.audio_utils import Normalize, Silent
samples,sr = get_audio(audio)
if self.threshold_silence:
from .karafan.audio_utils import Silent
samples = np.atleast_2d([samples])
samples = Silent(samples, sample_rate=sr, threshold_dB=self.silence_threshold_db)
samples = np.squeeze(samples, 0)
if self.dynamic_threshold: samples = self.dynamic_thresholding(
if self.dynamic_threshold:
samples = self.dynamic_thresholding(
samples,
multiplier=self.multiplier,
sample_size=self.sample_size,
method=self.fill_method,
kernel_size=self.kernel_size)
if self.normalize: samples = Normalize(samples,threshold_dB=self.normalize_threshold_db)
if self.normalize:
from .karafan.audio_utils import Normalize
samples = Normalize(samples,threshold_dB=self.normalize_threshold_db)
return samples, sr
@@ -297,4 +300,8 @@ def autotune_f0(f0, threshold=0.):
# Use the nearest value in array2
autotuned_f0.append(y)
# Return the result as a numpy array
return np.array(autotuned_f0, dtype="float32")
return np.array(autotuned_f0, dtype="float32")
def hz_to_mel(hz: "np.ndarray"):
# 1127 * np.log(1 + f0_min / 700)
return 2595 * np.log10(1 + hz / 700) # from wikipedia
+8 -9
View File
@@ -1,7 +1,8 @@
import onnxruntime
import librosa
import numpy as np
import soundfile
from ..audio import hz_to_mel
class ContentVec:
@@ -79,6 +80,7 @@ class OnnxRVC:
self.model = onnxruntime.InferenceSession(model_path, providers=providers)
self.sampling_rate = sr
self.hop_size = hop_size
self.f0_bins = 256
def forward(self, hubert, hubert_length, pitch, pitchf, ds, rnd):
onnx_input = {
@@ -102,8 +104,8 @@ class OnnxRVC:
):
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)
f0_mel_min = hz_to_mel(f0_min)
f0_mel_max = hz_to_mel(f0_max)
f0_predictor = get_f0_predictor(
f0_method,
hop_length=self.hop_size,
@@ -125,12 +127,9 @@ class OnnxRVC:
pitchf = f0_predictor.compute_f0(wav, hubert_length)
pitchf = pitchf * 2 ** (f0_up_key / 12)
pitch = pitchf.copy()
f0_mel = 1127 * np.log(1 + pitch / 700)
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * 254 / (
f0_mel_max - f0_mel_min
) + 1
f0_mel[f0_mel <= 1] = 1
f0_mel[f0_mel > 255] = 255
f0_mel = hz_to_mel(pitch)
f0_mel = (f0_mel - f0_mel_min)*(self.f0_bins-2)/(f0_mel_max - f0_mel_min) + 1
f0_mel = np.clip(f0_mel, a_min=1, a_max=self.f0_bins-1)
pitch = np.rint(f0_mel).astype(np.int64)
pitchf = pitchf.reshape(1, len(pitchf)).astype(np.float32)
+2 -1
View File
@@ -654,7 +654,8 @@ class RMVPE:
if self.is_half == True:
hidden = hidden.astype("float32")
f0 = self.decode(hidden, thred=thred)
f0[(f0 < f0_min) | (f0 > f0_max)] = 0
# f0[(f0 < f0_min) | (f0 > f0_max)] = 0
f0 = np.clip(f0, a_min=f0_min, a_max=f0_max)
return f0
def to_local_average_cents(self, salience, thred=0.05):