Using audioread to read a sequence of files and then combine

조회 수: 4 (최근 30일)
Benjamin Colbert
Benjamin Colbert 2019년 10월 21일
댓글: Ninad Kuware 2021년 11월 8일
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)

답변 (1개)

Stephen23
Stephen23 2021년 6월 28일
편집: Stephen23 2021년 6월 28일
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)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by