MATLAB Answers

MFCC extraction for audio files in a folder

61 views (last 30 days)
Hello, below is the code i m working on to extract mfcc features for all audio files in a folder. I want each file with it mfccs features in the term of columns or row, meaning each audio file with mfcc features dimensions(as a vector). If i have 36 audios files in a folder, i want to store the mfcc features of each file in an excel or anywhere with 36 columns or rows which correspond to audio 36 audio files numbers, and their rows or columns which correspond to mfcc features of each audio files, the dimensions of each audio file mfcc features must be the same. I tried with the following code but in vain, i really need help to figure out the problem in my code. The code is:
clc
clear all
file = dir ('D:\FOR AUDIO PREPARATION\F03&FC03\VOWEL_e\F03--FC03\F03\*wav');
M= length (file)
% file = dir ('*.wav');
%
% M= length (file);
NFFT = 128;
for k = 1:10
%pitch extraction
[speech,Fs]= audioread(fullfile('D:\FOR AUDIO PREPARATION\F03&FC03\VOWEL_e\F03--FC03\F03\',file(k).name));
% [speech,Fs]= audioread(file(k).name);
a=(speech);
[coeffs,delta,deltaDelta,loc] = mfcc(speech,Fs);
win = hann(1024,"periodic");
S = stft(imf,"Window",win,"OverlapLength",512,"Centered",false);
coeffs = mfcc(S,Fs,"LogEnergy","Ignore");
data(:,k) = coeffs(:);
end

  0 Comments

Sign in to comment.

Accepted Answer

jibrahim
jibrahim on 9 Dec 2020
Hi Camille,
The size of the output of mfcc, coeffs, is L-by-M for mono audio signals, where L depends on the audio input length, and M is the number of coefficients you asked for (controlled by the NumCoeffs parameter-value pair - it is 13 by default).
If your audio signals are not all of the same length, then L will be different for each file, and you won't be able to put the coefficients in a matrix like you are doing.
You either have to make sure all your signals are of the same length, or you will have to store the MFCC coefficients in a cell array rather than a matrix. For example:
files = dir ('*.wav');
data = cell(1, length(files));
for k = 1:length(files)
[speech,Fs]= audioread(files(k).name);
coeffs = mfcc(speech,Fs,"LogEnergy","Ignore");
data{k} = coeffs;
end

  1 Comment

Camille Dingam
Camille Dingam on 10 Dec 2020
Hello, thank you for your answer it is really helpful, so after storing the result in the cell array, the next step is to extract the mean of each column(13) belonging to each file to form just one row values of mfcc features for each file? And other question is if i want to extand the dimension from 13 to 60, what should i change in the code? Thank you again for your help, i really appreciate it.

Sign in to comment.

More Answers (1)

Camille Dingam
Camille Dingam on 10 Dec 2020
Hello, thank you for your answer it is really helpful, so after storing the result in the cell array, the next step is to extract the mean of each column(13) belonging to each file to form just one row values of mfcc features for each file? And other question is if i want to extand the dimension from 13 to 60, what should i change in the code? Thank you again for your help, i really appreciate it.

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!