This commit is contained in:
Si11ium
2020-10-07 15:21:45 +02:00
parent 5848b528f0
commit f296ba78b9
6 changed files with 78 additions and 39 deletions

View File

@ -76,9 +76,9 @@ class NormalizeMelband(object):
class AudioToMel(object):
def __init__(self, amplitude_to_db=False, power_to_db=False, **kwargs):
def __init__(self, amplitude_to_db=False, power_to_db=False, **mel_kwargs):
assert not all([amplitude_to_db, power_to_db]), "Choose amplitude_to_db or power_to_db, not both!"
self.mel_kwargs = kwargs
self.mel_kwargs = mel_kwargs
self.amplitude_to_db = amplitude_to_db
self.power_to_db = power_to_db

View File

@ -59,9 +59,9 @@ class ShiftTime(object):
# Set to silence for heading/ tailing
shift = int(shift)
if shift > 0:
augmented_data[:, :shift] = 0
augmented_data[:shift, :] = 0
else:
augmented_data[:, shift:] = 0
augmented_data[shift:, :] = 0
return augmented_data
else:
return x

View File

@ -0,0 +1,21 @@
from typing import Union
import numpy as np
class Normalize(object):
def __init__(self, min_db_level: Union[int, float]):
self.min_db_level = min_db_level
def __call__(self, s: np.ndarray) -> np.ndarray:
return np.clip((s - self.min_db_level) / -self.min_db_level, 0, 1)
class DeNormalize(object):
def __init__(self, min_db_level: Union[int, float]):
self.min_db_level = min_db_level
def __call__(self, s: np.ndarray) -> np.ndarray:
return (np.clip(s, 0, 1) * -self.min_db_level) + self.min_db_level