Skip to content

Instantly share code, notes, and snippets.

@f-rumblefish
Created April 4, 2020 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f-rumblefish/39d523c5bd8d7e0f9a25e6159c390ffa to your computer and use it in GitHub Desktop.
Save f-rumblefish/39d523c5bd8d7e0f9a25e6159c390ffa to your computer and use it in GitHub Desktop.
MFCC for Audio Cats and Dogs
# import library
import librosa
import numpy as np
# define the file name
wav_name = 'cat_1.wav'
# define the length of features
max_len = 20000
# load the wav file
file_data, file_rate = librosa.load(wav_name)
# get mfcc in 2D
mfcc_2D = librosa.feature.mfcc(y=file_data, sr=file_rate, n_mfcc=40)
# convert mfcc in 2D to mfcc in 1D
mfcc_1D = mfcc_2D.flatten()
# pad mfcc so that all files have features in the same length
mfcc_final = np.pad(mfcc_1D, (0, max_len - len(mfcc_1D)), 'constant')
print(mfcc_2D.shape, mfcc_1D.shape, mfcc_final.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment