Created
April 4, 2020 11:19
-
-
Save f-rumblefish/39d523c5bd8d7e0f9a25e6159c390ffa to your computer and use it in GitHub Desktop.
MFCC for Audio Cats and Dogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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