How to get the name of each file in the folder

5 visualizaciones (últimos 30 días)
Zhuoyi Ma
Zhuoyi Ma el 2 de En. de 2023
Respondida: jibrahim el 3 de En. de 2023
I want to extract the MFCC features of each .wav file. And I need to save the .mat file together with the name of .wav files.
e.g: hello.wav -> hello.mat
I tried using fileparts, but I found problems here:
Error using fileparts
Input must be a row vector of characters, or a string scalar, or a cellstr, or a string matrix.
Error in MFCC_extractor (line 5)
[filepath,name,ext] = fileparts(basedir);
basedir = dir('C:\Users\DELL\Desktop\Reshape/*.wav'); % .wav directory
for i = 1:numel(basedir)
[filepath,name,ext] = fileparts(basedir);
[y,Fs] = audioread(fullfile(basedir(i).folder, basedir(i).name));% read audio
audio_data{i} = y(:,1); % make mono
[mfcc_data{i},delta,deltaDelta,loc] = mfcc(audio_data{i},Fs,NumCoeffs=20,LogEnergy="ignore");% extract mfccs

Respuestas (2)

Image Analyst
Image Analyst el 2 de En. de 2023
[filepath,name,ext] = fileparts(basedir);
[y,Fs] = audioread(fullfile(basedir(i).folder, basedir(i).name));% read audio
fullFileName = fullfile(basedir(i).folder, basedir(i).name);
[filepath,name,ext] = fileparts(fullFileName);
[y,Fs] = audioread(fullFileName);% read audio
  2 comentarios
Image Analyst
Image Analyst el 2 de En. de 2023
fillOutputFileName = fullfile(filepath, [name, '.mat']);
save(fillOutputFileName, "mfcc_data");

Iniciar sesión para comentar.

jibrahim el 3 de En. de 2023
If you have access to Audio Toolbox, using an audioDatastore might simplify this. Here is an example (make sure the function myCustomWriter is on path):
% First, create a datastore that points to your audio files
ads = audioDatastore(basedir,IncludeSubfolders=true);
% Apply a transformation to the datastore. The transformed datastore
% extracts mfcc coefficients from the audio data
Fs =8000;
tds = transform(ads,@(x)mfcc(x,Fs,NumCoeffs=20,LogEnergy="ignore"));
% Write mfcc coefficients for each file to a MAT file
outputLocation = fullfile(tempdir,"myFeatures");
% If you have Parallel Processing Toolbox, set UseParallel to true to
% perform wrting on multiple workers
function myCustomWriter(coeffs,writeInfo,~)
% myCustomWriter(spec,writeInfo,~) writes mfccs to MAT files.
filename = strrep(writeInfo.SuggestedOutputName,".wav",".mat");


Más información sobre AI for Audio en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by