Make .wav signals same size?

4 visualizaciones (últimos 30 días)
Djordje Damnjanovic
Djordje Damnjanovic el 14 de Feb. de 2020
Comentada: Djordje Damnjanovic el 19 de Feb. de 2020
Hello everyone!
I have this problem. I need to read for example 60 wav signals, find the shortest one and cut all of them to the size of shortest.
Process of cut is like this: from the middle of the signal need to cut signal right and left equally to the size of shortest signal.
I upload picture as extra explanation.

Respuesta aceptada

Image Analyst
Image Analyst el 14 de Feb. de 2020
The "dir()" version of the code is probably what you want. So do the loop once to scan the files, calling audioread, then get the length, then scan again to do the cropping. Make sure you save into a different folder so you don't permanently destroy your input sound files. In short:
filePattern = fullfile(inputFolder, '*.wav');
files = dir(filePattern)
minLength = inf;
for k = 1 : length(files)
thisFileName = fullfile(inputFolder, files(k).name);
[y, fs] = audioread(thisFileName);
if length(y) > minLength
maxLength = length(y);
end
end
% Now scan again, doing the cropping
for k = 1 : length(files)
thisFileName = fullfile(inputFolder, files(k).name);
[y, fs] = audioread(thisFileName);
y = y(1:minLength);
outputFileName = fullfile(outputFolder, files(k).name);
audiowrite(...........
end
etc. Or something like that. Of course you need to assign inputFolder and outputFolder to some actual folders on your drive.
  2 comentarios
Djordje Damnjanovic
Djordje Damnjanovic el 19 de Feb. de 2020
Thank You! I think it is the right one!
Djordje Damnjanovic
Djordje Damnjanovic el 19 de Feb. de 2020
I do not know just this situation from the middle how to solve that?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by