Hi there
I am using below function for feature extraction. Using mfcc and melspectrograms in my model. Both outputs should be of similar dimension. There is not problem with mfcc alone but I am not getting why model is taking 5 dimensions inmelspectrogram. Can anyone figure It out plz
Regards
class FeatureExtractor(object):
def __init__(self, rate):
self.rate = rate
def get_features(self, features_to_use, X):
X_features = None
accepted_features_to_use = ('mfcc', ''melspectrogram')
if features_to_use not in accepted_features_to_use:
raise NotImplementedError("{} not in {}!".format(features_to_use, accepted_features_to_use))
if features_to_use in ('mfcc'):
X_features = self.get_mfcc(X,26)
if features_to_use in ('melspectrogram'):
X_features = self.get_melspectrogram(X)
return X_features
def get_mfcc(self, X, n_mfcc=13):
def _get_mfcc(x):
mfcc_data = librosa.feature.mfcc(x, sr=self.rate, n_mfcc=n_mfcc)
return mfcc_data
X_features = np.apply_along_axis(_get_mfcc, 1, X)
return X_features
def get_melspectrogram(self, X):
def _get_melspectrogram(x):
mel = librosa.feature.melspectrogram(y=x, sr=self.rate, n_fft=800, hop_length=400)[np.newaxis, :]
delta = librosa.feature.delta(mel)
delta_delta = librosa.feature.delta(delta)
out = np.concatenate((mel, delta, delta_delta))
return mel
X_features = np.apply_along_axis(_get_melspectrogram, 1, X)
return X_features
Here the shapes of X is (5984, 32000)