How do you concatenate two audio files horizontally? (.WAV)

17 次查看(过去 30 天)
I'm trying to merge two .WAV files together so that they can be played at the same time.
The problem is they may be of different frequencies as one may be a voice recording. I've learnt how to concat vertically but require some insight into the process of concatenating two separate audios horizontally.
Any help would be appreciated.

采纳的回答

Walter Roberson
Walter Roberson 2021-3-13
编辑:Walter Roberson 2021-3-13
[wav1, Fs1] = audioread('RockGuitar.wav');
[wav2, Fs2] = audioread('guitartune.wav');
maxFs = max(Fs1, Fs2);
rs1 = resample(wav1, maxFs, Fs1);
rs2 = resample(wav2, maxFs, Fs2);
maxlength = max(size(rs1,1), size(rs2,1));
rs1(end+1:maxlength,:) = 0;
rs2(end+1:maxlength,:) = 0;
horizontal_wav = [rs1, rs2];
size(horizontal_wav)
ans = 1×2
3195904 3
p = audioplayer(horizontal_wav(:,end-1:end), maxFs);
play(p)
You are going to need more work to be able to play the 3 or 4 channels simultaneously. Note that the channels have not been processed for Dolby Surround or Dolby DTS, but you could use them for front and back speakers, for example.
Remember to pay attention to the fact you are not promised that they are all the same number of channels, so horizontal concatenation like you asked for loses the boundaries between which channel came from which sound.
... And you did not ask to play them as separate stereo channels, and you did not ask that the respective channels be mixed together.
  5 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by