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

4 vues (au cours des 30 derniers jours)
sangeet sagar
sangeet sagar le 23 Mar 2018
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
  • # 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);
  2 commentaires
Ameer Hamza
Ameer Hamza le 21 Avr 2018
What is not working? You did not give error information. Your for-loops are also incorrect. For a possible solution see the answer below.

Connectez-vous pour commenter.

Réponses (2)

Ameer Hamza
Ameer Hamza le 21 Avr 2018

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( > 4 && == ".wav"   % only read file if filename is greater then four and extension is '.wav'
        count = count+1;
        [f{count} fs{count}] = audioread(; 

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

  2 commentaires
Jan le 21 Avr 2018

Or easier:

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

Connectez-vous pour commenter.

Dinesh Iyer
Dinesh Iyer le 27 Avr 2018
You can use the fileDatastore with the audioread as the Custom function.

Community Treasure Hunt

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

Start Hunting!

Translated by