function clips = saveSounds(y, fs, onsets, filename)

% Write the sounds after the onsets to the specified file with some
% space between them.

before = round(.01*fs);
chunksize = round(.75 * fs);
space = round(.5 * fs);

x = [];
y = y(:);

for i=1:length(onsets)-1
  x = [x ; y(onsets(i,1):onsets(i,2)) ; zeros(space,1)];
end

x = x * .9 / max(abs(x));
wavwrite(x, fs, filename);

if(nargout > 0) clips = x; end