How can I simultaneously loop through a folder and process an audio file and text file with the same name?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Re van Zyl
el 15 de Oct. de 2018
Respondida: Kevin Chng
el 15 de Oct. de 2018
Good day
I have a folder with 530 files, 265 audio files and 265 text files. Each text file match and audio file and they have the same name for example:
105_1b1_Tc_sc_Meditron.txt and 105_1b1_Tc_sc_Meditron.wav
&&
106_2b1_Pl_mc_LittC2SE.txt and 106_2b1_Pl_mc_LittC2SE.wav
I have written a code and tested it on a single set, but I am unsure how to write the code to loop through the entire folder and make sure that each time a matching set is used. The code I have written:
%% Code starts here
% read in file with textscan
fid = fopen('106_2b1_Pl_mc_LittC2SE.txt');
FC = textscan(fid,'%s','Delimiter','\n');
fclose(fid);
FC = FC{1};
% split all lines
FCsplit = regexp(FC, '(\S*)', 'match');
% columns to extract as double
ind1 = 1:2:3:4;
% prepare result arrays for double and string (as cell array)
D = zeros(length(FCsplit), length(ind1))
% loop over all columns to extract
for n = 1:length(ind1)
D(:, n) = cellfun(@(x) str2double(x(ind1(n))), FCsplit)
end
[X, Fs]=audioread('106_2b1_Pl_mc_LittC2SE.wav')
L = length(X);
t = [0:L-1]/Fs;
% plot(t,X);
L1 = length(D);
for k = 1:L1
idx = (D(k,1)<t) & (t<D(k,2));
l = length(X(idx));
time = t(idx);
Tw = time(length(time)) - time(1);
Crackle= D(k,3)
Wheeze = D(k,4)
%sef = feature_extract_f(X(idx), 44100, Tw, Crackle, Wheeze)
end
If possible can someone give me some guidance. I have already looked at How can I process a sequence of files, but the file names vary to much?
I also attached a text file, but unfortunately the .wav format is not supported.
Thank you in advance for your help.
Kind regards
2 comentarios
Kevin Chng
el 15 de Oct. de 2018
Hi,
Assume there are 265 text file, and 265 audio file are same name.
Therefore, i guess there are in same order of sequence in the folder.
F = dir('*.txt');
C = dir('*.wav');
Put them in the for loop
for i=1:1:length(F)
%open text file
fid = fopen(F(i).name);
% Your own algorithm
% Open Audio wave
[X, Fs]=audioread(C(i).name);
%your own algorithm
end
Respuesta aceptada
Kevin Chng
el 15 de Oct. de 2018
Hi,
Assume there are 265 text file, and 265 audio file are same name.
Therefore, i guess there are in same order of sequence in the folder.
F = dir('*.txt');
C = dir('*.wav');
Put them in the for loop
for i=1:1:length(F)
%open text file
fid = fopen(F(i).name);
% Your own algorithm
% Open Audio wave
[X, Fs]=audioread(C(i).name);
%your own algorithm
end
Help to accept it since it is working for you.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio and Video Data 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!