1

What I want to do is to receive sound from one mediasoup server. Mix it and then send it to another server. This seemed like a simple task, but for a couple days I have been struggling with it.

How I do it? I put audio I receive in <audio> tags And here is my code

      let audioContext = new (window.AudioContext || window.webkitAudioContext)();

      const audioElement = document.getElementById(this.consumer.id)
      const incomingSource = audioContext.createMediaElementSource(audioElement);

      this.filter = audioContext.createBiquadFilter();
      this.filter.type = "lowpass";
      this.filter.frequency.value = 1000;

      const outgoingStream = new MediaStreamAudioDestinationNode(audioContext);
      incomingSource.connect(this.filter);
      this.filter.connect(outgoingStream);
      this.outgoingTrack = outgoingStream.stream.getAudioTracks()[0];

And then I am sending this via mediasoup by using this.sendTransport.produce({track: this.outgoingTrack})

What I think I am doing is getting the sound I received then connecting the filter to this sound, then connecting the filter to the stream I want to forward and finally sending the track.

But that doesn't work so apparently I am doing something wrong. When I am doing this without filter like this:

      let audioContext = new (window.AudioContext || window.webkitAudioContext)();

      const audioElement = document.getElementById(this.consumer.id)
      const incomingSource = audioContext.createMediaElementSource(audioElement);

      const srcObject = incomingSource.mediaElement.srcObject;
      const outgoingTrack1 = srcObject.getAudioTracks()[0]

It works flawlessly but it is only forwarding the sound without any changes to it.

So how can I mix this sound?

Michał Bogusz
  • 376
  • 2
  • 12

0 Answers0