Using audioread to read a sequence of files and then combine

4 vues (au cours des 30 derniers jours)
Benjamin Colbert
Benjamin Colbert le 21 Oct 2019
Commenté : Ninad Kuware le 8 Nov 2021
I am am trying to read all wav files within a folder and then combine those files. I understannd audioread and audiowrite. I am stuggling to automate the processing of a sequence of files within a folder so that I only have to change the dirin name and can move to the next folder. The code here obviously doesn't work but trying to demonstrate what I want to do.
DirIn = 'C:\Users\24hr sound analysis\17';
eval(['filelist=dir(''' DirIn '/*.wav'')'])
for i = 1:length(filelist);
[f(i),fs] = audioread(strcat(DirIn,'/',filelist(i).name)); % read in wav file
end
combined = [f1;f(i)];
audiowrite('combined.wav',combined, fs)

Réponses (1)

Stephen23
Stephen23 le 28 Juin 2021
Modifié(e) : Stephen23 le 28 Juin 2021
Do NOT use EVAL for trivial code like this.
Use FULLFILE instead of concatenating text together.
P = 'C:\Users\24hr sound analysis\17';
S = dir(fullfile(P,'*.wav'));
for k = 1:numel(S)
F = fullfile(P,S(k).name);
[S(k).data,fs] = audioread(F);
end
M = vertcat(S.data); % comma-separated list
audiowrite('combined.wav', M, fs)

Community Treasure Hunt

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

Start Hunting!

Translated by