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

7 visualizaciones (últimos 30 días)
sangeet sagar
sangeet sagar el 23 de Mzo. de 2018
Comentada: kalyan chakravarthi el 16 de Jul. de 2022
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 comentarios
Ameer Hamza
Ameer Hamza el 21 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (2)

Ameer Hamza
Ameer Hamza el 21 de Abr. de 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(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 comentarios
Jan
Jan el 21 de Abr. de 2018

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 el 16 de Jul. de 2022
is it saying not enough enough arguements what to do now

Iniciar sesión para comentar.


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

Categorías

Más información sobre Measurements and Spatial Audio en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by