Skip to content

Commit

Permalink
Update feature.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sooftware authored Apr 9, 2021
1 parent 847587c commit aa3ab7f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions kospeech/data/audio/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def __init__(
assert platform.system().lower() == 'linux' or platform.system().lower() == 'darwin'
import torchaudio

self.amplitude_to_db = torchaudio.transforms.AmplitudeToDB()
self.transforms = torchaudio.transforms.MelSpectrogram(
sample_rate=sample_rate,
win_length=frame_length,
Expand All @@ -116,12 +115,11 @@ def __init__(
else:
import librosa
self.transforms = librosa.feature.melspectrogram
self.amplitude_to_db = librosa.amplitude_to_db
self.power_to_db = librosa.power_to_db

def __call__(self, signal):
if self.feature_extract_by == 'torchaudio':
melspectrogram = self.transforms(Tensor(signal))
melspectrogram = self.amplitude_to_db(melspectrogram)
melspectrogram = melspectrogram.numpy()

elif self.feature_extract_by == 'librosa':
Expand All @@ -132,7 +130,7 @@ def __call__(self, signal):
n_fft=self.n_fft,
hop_length=self.hop_length,
)
melspectrogram = self.amplitude_to_db(melspectrogram, ref=np.max)
melspectrogram = self.power_to_db(melspectrogram, ref=np.max)

else:
raise ValueError("Unsupported library : {0}".format(self.feature_extract_by))
Expand Down

0 comments on commit aa3ab7f

Please sign in to comment.