From b3c7031092705ef8bd138c387800466d6cf43852 Mon Sep 17 00:00:00 2001 From: 525750302 <46802084+525750302@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:37:19 +0900 Subject: [PATCH] Fixed a bug in the extract_feature function that was causing it to not work properly. --- utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 85fd3e2b..1255eaef 100644 --- a/utils.py +++ b/utils.py @@ -61,6 +61,7 @@ def extract_feature(file_name, **kwargs): mel = kwargs.get("mel") contrast = kwargs.get("contrast") tonnetz = kwargs.get("tonnetz") + result = np.array([]) try: with soundfile.SoundFile(file_name) as sound_file: pass @@ -82,7 +83,6 @@ def extract_feature(file_name, **kwargs): sample_rate = sound_file.samplerate if chroma or contrast: stft = np.abs(librosa.stft(X)) - result = np.array([]) if mfcc: mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T, axis=0) result = np.hstack((result, mfccs)) @@ -90,7 +90,9 @@ def extract_feature(file_name, **kwargs): chroma = np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T,axis=0) result = np.hstack((result, chroma)) if mel: - mel = np.mean(librosa.feature.melspectrogram(X, sr=sample_rate).T,axis=0) + # librosa.feature.melspectrogram function needs to determine which param the input X is. + # Here I add "y = X" to fix the bug which make extract_feature didn't work + mel = np.mean(librosa.feature.melspectrogram(y = X, sr=sample_rate).T,axis=0) result = np.hstack((result, mel)) if contrast: contrast = np.mean(librosa.feature.spectral_contrast(S=stft, sr=sample_rate).T,axis=0)