Mohamed Aboelfotoh
Published in : 2022-02-13
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!
Shilpa Date : 2022-02-26
Best answers
10
Best answers
10
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.
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now