Replacing scriptProcessorNode with AudioWorklet
Asked Answered
H

1

6

I am working on recording microphone input from the user and processing it. The problem is that I am using scriptProcessorNode to process data, but here it said that is has been deprecated and replaced with AudioWorklet.The problem is that there is no clear way to replace this functionality with AudioWorklet, and from all of the example projects with AudioWorklets from Google, none of them is doing anything with microphone input. Is there a way to replace this code with Audio Worklet? Here is the code that "should" be replaced.

    // Connect analyser
    this.options.source.connect(this.analyser);
    // Create ScriptProcessorNode
    this.scriptProcessorNode = this.options.context.createScriptProcessor(this.options.bufferLen, numChannels, numChannels);
    // Connect scriptProcessorNode (Theretically, not required)
    this.scriptProcessorNode.connect(this.options.context.destination);
    // Create callback to update/analyze floatFrequencyData
    var self = this;
    this.scriptProcessorNode.onaudioprocess = function (event) {
        self.analyser.getFloatFrequencyData(self.floatFrequencyData);
        self.update();
        self.store(event);
        self.monitor();
    };
    // Connect scriptProcessorNode
    this.options.source.connect(this.scriptProcessorNode);
Hasa answered 1/11, 2018 at 8:44 Comment(0)
G
1

I have a simple example of creating an AudioWorkletProcessor. You can check it here. It only works on Chromium, Firefox don't have support for AudioWorklet yet.

It's an example I've prepared to show a webpack error I'm having, so please check only the source code. If you run the project it will fail unless you comment audio-meter.js line 8 and uncomment line 11. The file audio-meter.worker.js is duplicated with the same content.

Ganesa answered 12/11, 2018 at 5:31 Comment(4)
I cannot access the link you attachedHasa
Hey, I was having some issues and I didn't really have time to debug it. I see audio-meter.js is trying to import audio-meter.worker.js but audio-meter.worker.js is not providing any default export. I am trying to test the site on localhost.Hasa
My bad, it works actually. What are you doing with the audio input?Hasa
Still nothing, but the idea is to generate a rxjs stream with the rms of the input. I'm trying to figure out how to test this. I'v seen this: github.com/mohayonao/web-audio-test-api but it doesn't support AudioWorklets. All ideas are wellcome. You have the original project here: bitbucket.org/alvaro_maceda/notoono but don't expect too much.Ganesa

© 2022 - 2024 — McMap. All rights reserved.