필터 지우기
필터 지우기

How do I read all the wav files in a directory from a single loop ?

조회 수: 8 (최근 30일)
sangeet sagar
sangeet sagar 2018년 3월 23일
댓글: kalyan chakravarthi 2022년 7월 16일
I have Emo-DB databse containing file name wav files with file name as following
1   03a01Ab.wav    
2   03a01Eb.wav   
3   03a01Fa.wav    
4   03a01Lb.wav    
5   03a01Nc.wav      
6   03a01Tc.wav     
7   03a01Wa.wav    
8   08a01Aa.wav     
9   08a01Ab.wav     
10   08a01Ec.wav  
11   08a01Fd.wav   
12   08a01Lc.wav    
13   08a01Na.wav     
14   08a01Td.wav   
15   08a01Wa.wav
16   08a01Wc.wav    
17   09a01Aa.wav  
18   09a01Ea.wav   
19   09a01Fa.wav      
20   09a01Lc.wav     
21   09a01Nb.wav
Here    
  • # Positions 1-2: number of speaker
  • # Positions 3-5: code for textspoken
  • # Position 6: emotion
  • # Position 7: if there are more than two versions these are numbered a, b, c ....
Now how do I read all these files using using audioread in a single loop. I tried the following code but it doesn't work:
for i=0
for j=0:0
for k=0:0
fid = fopen(filename,'a');
file =sprintf('%s%d%s%d%d.wav', 'D:\BTP\0 (1)\', i,'\',j,k);
[s, fs] = audioread(file);
end
end
end
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2018년 4월 21일
What is not working? You did not give error information. Your for-loops are also incorrect. For a possible solution see the answer below.

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

답변 (2개)

Ameer Hamza
Ameer Hamza 2018년 4월 21일

Instead of trying to create file names yourself, uou can use dir command to get list of all files in the current folder. Then use the list to read all files with an extension of '.wav'.

files = dir;
count = 0;
for i = files'
    if length(i.name) > 4 && i.name(end-3:end) == ".wav"   % only read file if filename is greater then four and extension is '.wav'
        count = count+1;
        [f{count} fs{count}] = audioread(i.name); 
    end
end

This script will load all data in cell arrays f and fs.

  댓글 수: 2
Jan
Jan 2018년 4월 21일

Or easier:

FileList = dir('D:\BTP\0 (1)\*.wav');
for File = FileList'
   count                 = count + 1;
   [f{count}, fs{count}] = audioread(File.name); 
end
kalyan chakravarthi
kalyan chakravarthi 2022년 7월 16일
is it saying not enough enough arguements what to do now

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


Dinesh Iyer
Dinesh Iyer 2018년 4월 27일
You can use the fileDatastore with the audioread as the Custom function.
https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.filedatastore.html

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by