I need to convert my ScriptProcessor logic to an AudioWorklet. The ScriptProcessor process is very easy and only a few lines of code, but I'm having a hard time converting it over to an AudioWorklet.
Here is my current process (the stream comes from userMedia):
var context = new AudioContext();
var microphone = context.createMediaStreamSource(stream);
var processor = context.createScriptProcessor(0, 1, 1);
microphone.connect(processor);
processor.connect(context.destination);
and then I send the data to a worker:
processor.onaudioprocess = function (event) {
var array = event.inputBuffer.getChannelData(0);
realTimeWorker.postMessage({cmd: 'encode', buf: array})
};
I just need the AudioWorklet to process the data in the same way the ScriptProcessor does it, and then send the same data to the worker.
How could I convert this process to an AudioWorklet?