How to play and merge/mix 2 wav files

29 views (last 30 days)
AM
AM on 28 Nov 2016
Edited: AM on 7 Dec 2016
Hi,
Basically I want to merge the two wav files so that both music or voice annotates and play the a sound(i.e., you can hear both the voice and the music), and than save as a new wav file.
I am thinking of creating a merge/play button, but I do not know how to go about it. Any help would be much appreciated. Thank you.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2016
With regards to a Merge/Play button: create the button ahead of time in GUIDE, but set the default properties for it as 'Visible', 'off' . Then, in your code, as soon as you have verified that you have both inputs so the conditions are right for allowing merging, set the button 'Visible' property to 'on'.
  2 Comments
Walter Roberson
Walter Roberson on 29 Nov 2016
You should not use two audio players at the same time, as you have little control over synchronizing them. If your input is at two different sampling frequencies then you should resample() the lower rate one to a higher rate.
nrow = max(size(data1, 1), size(data2, 1));
out = zeros(nrow, 2);
out(1 : size(data1, 1), 1) = data1(:,1);
out(1 : size(data2, 1), 2) = data2(:,1);
now you can play out and the two will appear on left and right ear.
Walter Roberson
Walter Roberson on 30 Nov 2016
Please post your current version.
Are you input sounds mono or stereo?
Are they to be played one on the left channel and one on the right channel, or are they to be averaged together?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!