% function zeropad % un-mute this line to convert to a function % Last amended: 19 March 2019 by P. Demonte % SPECIFY FOLDER PATHWAYS dir_speech = 'C:\Users\SAP152\Desktop\Matlab Scripts\dir_In\dir_In_Speech\'; % location of input files dir_speech2disk = 'C:\Users\SAP152\Desktop\Matlab Scripts\dir_Out\dir_Out_Speech\';% location for output files % List and count the total number of .wav files in the dir_speech folder wavs = dir(fullfile(dir_speech, '*.wav')); nb_wavs = length(wavs); % ZERO-PADDING OF SPEECH AUDIO FILES % Note: audio files need to be less than 3.5 seconds to start with for w = 1:nb_wavs [sig_speech, fs] = audioread(fullfile(dir_speech, wavs(w).name)); [~,name,ext] = fileparts(wavs(w).name); % VERSION FOR 5 SECOND LONG .WAV FILES AFTER ZERO PADDING name2 = regexprep(name,'_0','_5'); % amend filename containing '_0' (from previous application of EndPoint.m) NewName = sprintf('%s%s',name2,ext); % add '_5' to file name upfront of '.wav' NZ_front = fs*1; % number of samples required for 1 s of padding sig_speech = [zeros(NZ_front,1); sig_speech]; % add zero padding to front end if length(sig_speech) < (fs*5) NZ_tail = (fs*5)-length(sig_speech); % calculation for tail end zero padding sig_speech = [sig_speech; zeros(NZ_tail,1)]; % add zero padding to tail end end audiowrite(fullfile(dir_speech2disk, NewName), sig_speech, fs); % save file with new name end