Web Audio: How to set different destination than speakers?

Viewed 327

I struggle to understand how – using one AudioContext – I would achieve the following:

  1. I use createMediaStreamSource to create the source of the context – works.

  2. I then connect a volume node to the source – works.

  3. I then want to create TWO outputs: One is the "standard" output (the speakers) and the second would be used to feed into a mediaRecorder

I struggle with the 3rd point. How do I specify a different output than speakers? Is the output still a stream I can feed into MediaRecorder?

1 Answers

From what you describe, I assume that you have some code that looks like this:

mediaStreamAudioSourceNode
    .connect(gainNode) // your volume node
    .connect(audioContext.destination);

You just need to add another MediaStreamAudioDestinationNode and use that as an additional output.

const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);

gainNode.connect(mediaStreamAudioDestinationNode);

const mediaRecoder = new MediaRecorder(mediaStreamAudioDestinationNode.stream);
Related