user

Mohamed Aboelfotoh

13 Feb 2022

How to get audio input and audio output as one stream?

Javascript

I'm familiar with the MediaStream Recording API, however after doing some research, I'm not sure if I can use it to collect both input and output in JavaScript applications.

Basically, I'd like to record both my microphone and the audio that I get (basically the audio which comes from the other user mic).

Any assistance in pointing me in the correct path would be greatly appreciated!

Comments

Shilpa

26 Feb 2022

github

You may do it by the following code, (Using MediaStream Recording API approach)

var audioContext = new AudioContext();
var mediaStreamDest = new MediaStreamAudioDestinationNode(audioContext);
document.querySelectorAll("audio").forEach((e) => {
 var mediaElementSource = new MediaElementAudioSourceNode(audioContext, { mediaElement: e });
 mediaElementSource.connect(mediaStreamDest);
});
console.log(mediaStreamDest.stream.getAudioTracks()[0]);

The above line, given in the console log will get the first audio track from your MediaStream. 

stream.addTrack(mediaStreamDest.stream.getAudioTracks()[0])

After that, it will mix up audio streams into one stream.

 

Shivesh Singh

12 Aug 2022

Hi Aboelfotoh, were you able to collect audio output? If yes could you please throw me some pointers how did you do it?

© 2024 Copyrights reserved for web-brackets.com