admin管理员组

文章数量:1292385

I have audio files and I am using Web Audio API to play them on browser. Now I want to play all the audio files simultaneously.

I got audio buffers for all the audio files using Web Audio API. I can loop through all and can play them but I want to merge all the audio buffers into one single audio buffer and then play it.

Does anyone have an idea to merge two audio buffers in Web Audio API?

I have audio files and I am using Web Audio API to play them on browser. Now I want to play all the audio files simultaneously.

I got audio buffers for all the audio files using Web Audio API. I can loop through all and can play them but I want to merge all the audio buffers into one single audio buffer and then play it.

Does anyone have an idea to merge two audio buffers in Web Audio API?

Share Improve this question edited Aug 13, 2019 at 8:10 Sylens 1,1778 silver badges31 bronze badges asked Jan 20, 2016 at 10:51 user3759750user3759750 1533 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

If you want to play all of the simultaneously, just connect each of your buffers to context.destination (or most any other node that is connected to the destination) and start them all at the same time.

If you sum two or more audio PCM arrays, i.e. buffer1[i] + buffer2[i] for each sample, you will have a third audio containing both sounding together.

You can even use a multiply factor over each track to control its volume, for example.

Hope this helps. This is just the begining.

If you need just to play it you should to connect both of sources to destination.

To really merge two buffers into another one, you can use offlineAudioContext or merge arrays yourself like this https://github./audiojs/audio-buffer-utils

本文标签: javascriptWeb Audio APImerge two audio buffersStack Overflow