how do i read multiple audio file from different files name ?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i have a folder about 136 subfolders which have different names
f1
f2
.
.
.
.
f136
and each subfolder has 10 audio file
these audio files have the same name for whole subfolders
f1 [ sa1 sa2 ....... sa10]
f2 [sa1 sa2 .... sa10]
.
.
f136 [sa1 sa2 ... sa10]
so i need to read them in one matrix
can anyone help me
i will be appreciate
1 Commento
Stephen23
il 23 Dic 2020
"so i need to read them in one matrix"
Does your computer have enough memory to store all of the imported data in one array? Or for that matter, in separate arrays?
Risposta accettata
Walter Roberson
il 23 Dic 2020
finfo = dir();
finfo(~[finfo.isdir]) = []; %get rid of non-folders
finfo(ismember({finfo.name}, {'.', '..'})) = []; %get rid of . and ..
foldernames = {finfo.name};
numfolders = length(foldernames);
folderdata = cell(numfolders,3);
for foidx = 1 : numfolders
thisfolder = foldernames{foidx};
dinfo = dir(fullfile(thisfolder, '*.wav'));
thesenames = fullfile(thisfolder, {dinfo.name});
numfile = length(thesenames);
thisdata = cell(numfile,1);
thisfs = zeros(numfile,1);
for fiidx = 1 : numfile
[thisdata{fiidx}, thisfs(fiidx)] = audiread(thesenames{fiidx});
end
folderdata{foidx, 1} = thisdata;
folderdata{foidx, 2} = thisfs;
folderdata{foidx, 3} = thesenames;
end
Output from this is an N x 3 cell array where N is the number of folders. The first column of the cell array, folderdata{K,1} is itself a cell array with one entry per file in the folder that is the audio data. The second column of the cell array, folderdata{K,2} is a vector of sampling frequency data, one for each WAV file in the folder. The third column of the cell array, folder{K,3} is a cell array of file names that were read from in the folder.
This code does not assume that the number of samples is exactly the same for each input file. It also does not assume that the sampling frequency is the same for each file, and it does not assume that the number of channels is the same for each file.
It is not clear to me what your desired output is. You have 136 folders, each with 10 files, number of samples per file is unknown, number of channels per file is unknown. Even assuming that you had exactly the same number of samples per file and that there is only one channel per file, you would still be looking at 136 x 10 x number of samples, but you kind of implied that you expect a 2D array rather than a 3D array.
0 Commenti
Più risposte (2)
weikang zhao
il 23 Dic 2020
You need a loop body, the loop body continuously generates the path of the audio file.
Run the following script and you will understand.
for i=1:136
for j=1:10
filename=['f',num2str(i),'\sa',num2str(j),'.wav'];
disp(str);
%code to read the audio file %
end
end
have fun!
4 Commenti
weikang zhao
il 23 Dic 2020
you can get all the names of the subfolder by "dir" function, for example
X=dir;
X will contain information about all subfolders and files in the current folder, X is a struct array, and you can traverse the 'name' field of X.
jibrahim
il 23 Dic 2020
If you have access to Audio Toolbox, there is no need for much custom code to accomplish this. Just use audioDatastore.
From the top folder:
ads = audioDatastore(pwd,'IncludeSubfolders',true);
data = readall(ads);
data is a cell array with the audio from all files. If all entries in data have the same dimensions, you can concatenate the signals in a matrix.
0 Commenti
Vedere anche
Categorie
Scopri di più su Audio and Video Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!