2

Few weeks ago I wrote WebRTC browser client using mediasoup library. Now I am in middle of rewriting it as a NodeJS client.

I am stuck with one thing. I want to receive multiple WebRTC audio souroces, mix them into single track then apply some filters(eg. biquad filter) and then resend this track via WebRTC. Like on this diagram: enter image description here

With browser I could achieve this using Web Audio API this is the code I used:

this.audioContext = new AudioContext();
this.outgoingStream = this.audioContext.createMediaStreamDestination();
this.addSoundFilter();
this.mixedTrack = this.outgoingStream.stream.getAudioTracks()[0];
this.handleIncomingSound();

addSoundFilter() {
  this.filter = this.audioContext.createBiquadFilter();
  this.filter.type = "lowpass";
  this.filter.frequency.value = this.mapFrequencyValue();

  this.gainer = this.audioContext.createGain();
  this.gainer.gain.value = this.mapGainValue();
}

handleIncomingSound() {
  this.audios.forEach((audio, peerId) => {
    this.filterAudio(audio);
  });
}
filterAudio(audioConsumerId) {
  let audio = this.audios.get(audioConsumerId);
  const audioElement = document.getElementById(audio.id);
  const incomingSource = this.audioContext.createMediaStreamSource(
    audioElement.srcObject
  );

  incomingSource.connect(this.filter).connect(this.gainer).connect(this.outgoingStream);
}

And with this code I could then send this.mixedTrack via WebRTC

However in NodeJS there is no WebAudioApi. So how this can be achieved or if it's even possible to do it?

Michał Bogusz
  • 376
  • 2
  • 12

0 Answers0