MATLAB: How can I merge to wav files with a pause of 3 seconds between them

mergewav. fileswith pause

i want to merge 2 wav-files but i need a pause of 3 seconds between them. How can I do that?

Best Answer

Supposing that the samples are in wav1 and wav2 and that the respective sampling frequencies are fs1 and fs2, then
merged_fs = max(fs1, fs2);
merged_wav = [reshape(wav1, fs1, merged_fs); zeros(merged_fs * 3, size(wav1, 2); reshape(wav2, fs2, merged_fs)];
This can be made simpler if the two are the same sampling frequency, fs
merged_wav = [wav1; zeros(fs * 3, size(wav1, 2)); wav2];
Note: this code expects that the wav files have the same number of channels.