I would like to modify the microphone input in real-time using an AudioWorklet
, in a chrome extension.
For a simple example, I just want to transmit an oscillator wave, like in this plnkr, where one is transmitted to the output
.
I first create the worklet:
await audioCtx.audioWorklet.addModule(WORKLET_PATH);
this.worklet = new AudioWorkletNode(audioCtx, 'oscillator');
this.worklet.connect(audioCtx.destination);
Then, I connect a microphone:
this.microphoneStream = await navigator.mediaDevices.getUserMedia({audio: true});
this.microphone = audioCtx.createMediaStreamSource(this.microphoneStream);
console.log('microphone', this.microphone.mediaStream.getTracks()[0].label);
this.microphone.connect(this.worklet as AudioWorkletNode);
And in the example plnkr, in processor.js
, instead of modifying the output I modify the input, setting line 15 to be:
const output = inputs[0];
But unfortunately, that does not modify the microphone. If I just playback the microphone audio, I can't hear the oscillator