フィルターのクリア

Using audioread to read a sequence of files and then combine

3 ビュー (過去 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 Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by