Iterate speech frames through all the audio file in the folder

5 views (last 30 days)
Hello, i have split audio file into frames and i want to iterate all the frames though all the audio file in the folder. After iterate, i want to apply feature like mfcc(calculate the mean) of all the audio file and put it in a matrix of rows and conlums(each row is mfcc mean for each file). Below is the code i m trying to make as what i need. Any help please.
clc;
clear all;
% Specify the folder where the files live.
myFolder = '/MATLAB Drive/AUDIO2/LONGhead/FC03_1head';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
AudioArray = cell(1, numel(theFiles));
i=1;
j=1;
o=1;
r=1;
u=1;
for k = 1 : numel(theFiles) % NUMEL is more direct than LENGTH
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
AudioArray{k} = audioread(fullFileName);
[speech, fs] = audioread(fullFileName);
% do framing
f_d = 0.03;
f_size = round(f_d * fs);
n = length(speech);
n_f = floor(n/f_size); %no. of frames
temp = 0;
for i = 1 : n_f
frames = speech(temp + 1 : temp + f_size);
%frames = X1(temp + 1 : temp + f_size);
temp = temp + f_size;
y=mfcc(frames, fs);
% z(i, :)=max(fwht(frames))
Z(i, j)=[mean(y)];
end
end

Accepted Answer

jibrahim
jibrahim on 13 Dec 2021
Hi Camille,
The function mfcc breaks the signal into frames for you, so you do not need to perform the frame processing yourself. Also, consider using an audioDatastore, as it will probably simplify your file handling logic.
Here is an example:
% This datastore points to all your audio files
ads = audioDatastore(pwd,'Includesubfolders',true);
numFiles = numel(ads.Files);
frameLength = 0.03; % in seconds
numCoeffs = 13;
avrgValues = zeros(numFiles,numCoeffs);
for index=1:numFiles
% Read an audio file
[x,myInfo] =read(ads);
% Take the first channel of audio here
x = x(:,1);
fs = myInfo.SampleRate;
winLength = round(frameLength*fs);
coeffs = mfcc(x,fs,"Window",hann(winLength,'periodic'),'NumCoeffs',13,'OverlapLength',0,'Logenergy','ignore');
avrgValues(index,:) = mean(coeffs);
end
  3 Comments
jibrahim
jibrahim on 13 Dec 2021
If you are using a toolbox function for LPC computation, you should check the help of that function - it might have a window/frame parameter. If you are using your own code for LPC, then you might have to perform framing yourself and then performing your custom computations; it depends on your algorithm. The way you were performing framing looks good to me. You can also consider looking into the buffer function. It will break your signal into frames for you.

Sign in to comment.

More Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!