need some help with MFCC feature extraction on librosa. My goal is to calculate MFCC from 160 audio files and use the output to train a convolutional neural network. But I'm having some issues with the code. I'm primarily a c++ user, so python is still tripping me up a bit.
My project is classifying songs based on time period (dataset is songs from 1950's to now). My goal is to extract the features and then train a CNN to predict the time period a song is from.
To start, I used glob to create a list of 160 mp3 files and saved it in the audio_files variable. Then, I looped through audio_files, loaded each mp3 file using librosa.load, and then calculated the MFCC. The issue is whenever I stop the loop before it finishes and try to print out the mfcc1 variable, it only outputs the last MFCC matrix it calculated. I need it to save all the MFCC data for each mp3 file it loops through. In the end, I want to use this data to feed it to the CNN model I'm building. Any tips on this? thank you
I saw some people were using CSV files that includes information about each audio file to loop over each row. Is this necessary? I see that you can make a dataframe that way with all the MFCC data about each file all in one place.
And I know that mfcc1 is of type numpy.ndarray, will this format work for the CNN? Thank you all again
import librosa
import librosa.display
import IPython.display as ipd
import matplotlib.pylab as plt
import os
from glob import glob
%matplotlib inline
from sklearn.preprocessing import minmax_scale
audio_files = glob('/Users/wt56/Downloads/522 Dataset/*.mp3')
for files in audio_files:
print(files)
for file in audio_files:
x, sr = librosa.load(file)
mfcc1 = librosa.feature.mfcc(y=x, sr=22050)
print(mfcc1)