how can i load multiple/all audio files(.wav) in matlab ? all files have different names.

18 views (last 30 days)
i have a folder containing a number of audio files. i want to load them in a loop so that each audio signals can undergo some operations that i intend to perform.

Accepted Answer

KSSV
KSSV on 20 Oct 2022
audioFiles = dir('*.wav') ;
N = length(audioFiles) ;
for i = 1:N
file - audioFiles(i).name ;
% do what you want
end
  3 Comments
Stephen23
Stephen23 on 14 Aug 2024
Edited: Stephen23 on 14 Aug 2024
@Hongmiao Yann: in the fourth line you should replace the minus with equals:
file = audioFiles(i).name;
It allocates one filename to the variable FILE.

Sign in to comment.

More Answers (1)

jibrahim
jibrahim on 20 Oct 2022
I recommend using audioDatastore for such tasks:
% specify your folder
folder = fullfile(matlabroot,'toolbox','audio','samples');
% Create an audio datastore that points to the specified folder.
ADS = audioDatastore(folder, IncludeSubfolders=true)
% While the audio datastore has unread files, read consecutive files
% from the datastore. Use progress to monitor the fraction of files read.
while hasdata(ADS)
data = read(ADS);
fprintf('Fraction of files read: %.2f\n',progress(ADS))
end

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!