필터 지우기
필터 지우기

"audioread" multiple audio files in a folder

조회 수: 13 (최근 30일)
Daeyeon Koh
Daeyeon Koh 2021년 12월 29일
답변: jibrahim 2021년 12월 29일
Hi.
I want to analyze spectrograms of multiple audio files in a folder.
Audio files share the word "SPTGRM" in their names.
Audio files are stereo-type and I will take one channel data.
As shown in the code below, I tried to save these files in the directory and save their data in "Spectrogram Data", but the following error occurred.
[ Error using audioread (line 90)
The filename specified was not found in the MATLAB path. ]
How can I solve this error?
clear all;
audio_files = dir('C:\Users\KOH\Desktop\MATLABcode\Soundsample\SPTGRM*.wav')
for i=1:numel(audio_files)
[y,Fs] = audioread(audio_files(i).name);
SpectrogramData(:,i)=y(:,1);
end
  댓글 수: 1
Stephen23
Stephen23 2021년 12월 29일
Why are you using CLEAR ALL? Does your program really need to remove all cached functions from memory, thus slowing down MATLAB? (hint: no). Use CLEARVARS if required, not CLEAR.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2021년 12월 29일
편집: Stephen23 2021년 12월 29일
You need to tell AUDIOREAD the filepath, otherwise it does not know where to find the files.
P = 'C:\Users\KOH\Desktop\MATLABcode\Soundsample';
S = dir(fullfile(P,'SPTGRM*.wav'));
for k = 1:numel(S)
F = fullfile(P,S(k).name); % you forgot this
[y,Fs] = audioread(F);
S.data(k) = y;
end

추가 답변 (2개)

Chunru
Chunru 2021년 12월 29일
clear all;
audio_files = dir('C:\Users\KOH\Desktop\MATLABcode\Soundsample\SPTGRM*.wav')
for i=1:numel(audio_files)
% You need to specify the folder as well
%[y,Fs] = audioread(audio_files(i).name);
[y,Fs] = audioread(fullfile(audio_files(i).folder, audio_files(i).name));
SpectrogramData(:,i)=y(:,1);
end

jibrahim
jibrahim 2021년 12월 29일
For future reference, I recommend you use audioDatastore:
You won't have to worry about finding files. for example:
ads = audioDatastore('C:\Users\KOH\Desktop\MATLABcode\Soundsample','IncludeSubfolders',true);
allSignals = readall(ads) % this reads all the audio files in one shot

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by