Iterate speech frames through all the audio file in the folder

조회 수: 5(최근 30일)
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.
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);
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
% 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));
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)];

채택된 답변

jibrahim 2021년 12월 13일
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);
  댓글 수: 3
Camille Dingam
Camille Dingam 2021년 12월 17일
Thank you very much, it is really helpful

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by