MATLAB: How to truncate number of sample in audiofiles using audioDatastore function in MATLAB

Audio ToolboxaudiodatastoreMATLAB

Hi all
I am using audiodatadatastore function to classify my speech signal using wavelet scattering . Unfortunately all my audio files are having different length or sample size. I want to make it uniform for all files.
I did try following
% while hasdata(ads)
% [data,info] = read(ads);
%
% if length(data)<45000
% data=[data;zeros(45000-length(data),1)];
% else
% data=data(1:45000);
% end
% end
But that’s of no use. Help is highly appreciated.

Best Answer

data(45001, :) = 0;
data = data(1:45000, 1);
No if needed, and handles multiple channels converting to single channel.
Related Question