Can I capture and edit audio stream locally before it hits another app?

155 views Asked by At

Good afternoon! In this implementation I'm using electron and javascript with webRTC.

To elaborate a bit on the question, I understand what I'm doing up to the point of obtaining a stream from the StreamHandler and calling mediaDevices.getUserMedia. Once I have that stream I have successfully added AudioContext to create filters, adjust gain, etc. I've heard these changes taking place on the audioDestination device as well. So all is good up to that point. So my question now is how do I then place that edited audio stream back on it's way to wherever it might go? A specific example would be, let's say I captured the stream of my main microphone and I want to adjust the gain before, say, the audio makes it to discord, twitch, etc.

If I'm visualizing the process I think

Mic Input ---> Grab Stream ---> Edit Stream ---> Continue output to 3rd party app.

But what seems to happen is the stream creates a separate channel and will only play on my own output devices as there is no destination for me to choose from devices that points to where my audio was already heading. Please understand I am still figuring out how all of this works. I'm also happy to change or edit the question to better meet the standards, just let me know.

UPDATE: I'm adding the constructor and updateStream functions of my code. Constructor is where I'm grabbing the media stream from the local machine and update stream is being called when a button is clicked to activate changes on the audio and play them to the output. Where I'm stuck is that the updates make sounds when I play them through headphones or speakers, but I don't know how to get the stream to go back and play through the mentioned apps above.

  constructor(navigator, deskCap, constraints) {
    this._navigator = navigator;
    this._constraints = constraints;
    this._desktopCapturer = deskCap;
    this._mainStream = new MediaStream();

    // Call our object setup functions
    this.getAudioSources();
    navigator.mediaDevices.getUserMedia(constraints).then((media) => {
      
      this._mainStream = media;
      });

    }); 
  }

  updateStream = () => {
    let stream = this._mainStream;
    
    const audContext = new AudioContext(); // Electron AudioContext

    const source = audContext.createMediaStreamSource(stream);
    const audDest = audContext.createMediaStreamDestination();
    const audSource = audContext.createMediaStreamSource(stream);
    
    const gainNode = audContext.createGain();
    let x = parseFloat(this._outputVolume);

    if(!isNaN(x)) {
      gainNode.gain.value = x;
    } else {
      gainNode.gain.volume = 0.33;
    }
    gainNode.connect(audDest);

    this._mainStream = audDest.stream;
}
0

There are 0 answers