When I extract one file of audio I get an array of Spectogram Array Shape: (128, 87). When I try to extract from a list of files 80 audio files I get (80 , 128) but i want an array like these (80, 128, 87). Where I am going wrong in my Code
def get_features(y, sr=fs):
melspectrogram = librosa.feature.melspectrogram(y, sr=fs)
feature_vector = np.mean(melspectrogram,1)
return feature_vector
Creating a feature vector
# Load audio files, calculate features and create feature vectors
feature_vectors = []
sound_paths = []
for i,f in enumerate(files):
print ("get %d of %d = %s"%(i+1, len(files), f))
try:
y, sr = librosa.load(f, sr=fs)
y/=y.max() #Normalize
if len(y) < 2:
print("Error loading %s" % f)
continue
feat = get_features(y, sr)
feature_vectors.append(feat)
sound_paths.append(f)
except Exception as e:
print("Error loading %s. Error: %s" % (f,e))
print("Calculated %d feature vectors"%len(feature_vectors))
Standardization
# Scale features using Standard Scaler
scaler = StandardScaler()
scaled_feature_vectors = scaler.fit_transform(np.array(feature_vectors))
print("Feature vectors shape:",scaled_feature_vectors.shape)