How to Cut multiple files from multiple folders in a for loop? Then return them to their own folders containing those cuts.

2 visualizaciones (últimos 30 días)
I have this working section that I have run all my other m files for, but i can only do it for the 12 2sec cuts of the 1st wav file under the folder directory named basson.....the Basson folder has 10 total wav files in it though.
I would like to get this for loop to work through all of the main 4 folders of wav files and slit them all up into 2sec clips,? any suggestions would help greatly!
got to have all this cut up so i can compare each data set later in program......
only other way i can think of is hard coding it, but it was going upwards of 800+ lines! ha
that line gives me files like, 3Basson1.wav, 3Basson2.wav........to 12
hopefully i worded this correctly....
Thanks again
file_name=sprintf('%dBassoon%d.wav',3,i) %can this be changed to %d%dBassoon%d.wav, "something to increment them?",i)
%----------------------------------------------------
%what i have so far working for the very first of 10 wav files in that folder
filename='C:\Users\......\Bassoon\01_AchGottundHerr_bassoon.RESYN.wav'; %does this need to be a dir?
[y, fs] = audioread(filename);
k=ceil(length(y)/(2*fs));
mkdir Cut_Bassoon
% mkdir Cut_Clarinet
% mkdir Cut_Saxphone
% mkdir Cut_Violin
s=2*fs;
n = length(y);
for i = 1: (k-1)
file_name=sprintf('%dBassoon%d.wav',3,i);
file_name=strcat('C:\Users\.......\Cut_Bassoon\', file_name);
audiowrite(file_name,y((s*(i-1)+1): (s*i)),fs); % this does the actual segmenting into 2sec and sends to that dir
end

Respuesta aceptada

Paul Hoffrichter
Paul Hoffrichter el 4 de Dic. de 2020
You can recursively find all files with a .wav extension using code from here:
But without the metadata in some of the .wav files that you create, it appears that you have to handle separately the first .wav file that has the metadata from the rest that do not.
  4 comentarios
morgan mcvay
morgan mcvay el 7 de Dic. de 2020
Editada: morgan mcvay el 7 de Dic. de 2020
Thankyou, over the past few days I have greatly increased my MATLAB performance, and i ended up taking some of the suggestions from the example code link you provided, I ultimetly used a dir search and threw then resorted them into new folder using 4 for loops.......not the most efficient! but it worked! haha
Point being, i wouldnt have figured it out without your link, so thank you.
filenameB=dir('C:\Users...........\*.wav');
filenameC=dir('C:\Users\........\*.wav');
filenameS=dir('C:\Users.........\*.wav');
filenameV=dir('C:\Users\..........*.wav');
mkdir Cut_Bassoon
mkdir Cut_Clarinet
mkdir Cut_Saxphone
mkdir Cut_Violin
for c = 1:numel(filenameC)
Name = filenameC(c).name;
[y, fs] = audioread(Name);
k=ceil(length(y)/(2*fs));
s=2*fs;
t = 1;
for i = 1: (k-1)
file_name = ['Clarinet_CUT' num2str(t) '_',Name];
audiowrite(file_name,y((s*(i-1)+1): (s*i)),fs);
t = t + 1;
end
end
% and repeted this 3 more times for each file.........

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by