javascriptaudioweb-audio-apirecorderaudio-worklet

Choose web api for audio recording


The task is to implement a recorder based on the standard web audio api. Having carefully studied both ways ScriptProcessorNode.onaudioprocess & AudioWorkletProcessor.process did not come to a final decision. It is officially said that onaudioprocess has been deprecated since 2014 and a full replacement is audio workers. I'm new to javascript and maybe the question sounds stupid, but why is there an active use of onaudioprocess to this day?

Let's dive into the details. AudioWorkletProcessor api is available for 73% of users, while onaudioprocess api for 93%. In the next 2 years, we can hope for a 10 percent increase. (safari users). There are many projects, articles, solutions using onaudioprocess. Even specific tasks can be solved simply by using onaudioprocess. Such solutions are not possible for AudioWorklet. AudioWorklet documentation is poor and few mentions on the internet. For example, I still don't understand why a WebWorker knows what a blob is, but AudioWorklet doesn't (devTools exception: Uncaught ReferenceError: Blob is not defined). In the typescript, there are long-open cases for declaration types of basic functionality. All this creates the impression that onaudioprocess is more lively than AudioWorklet. Perhaps the AudioWorklet is more productive but difficult to implement, or is the web audio api not needed by the javascript community? Explain why I should choose AudioWorklet according to the official recommendation?


Solution

  • You are asking many questions here. First, you'll be pleased to know that Safari has implemented AudioWorklets. See https://wpt.fyi/webaudio.

    Second WebWorkers and Worklets are different things with different capabilities. AudioWorklets are Worklets so AudioWorklets only get Worklet things, not WebWorker things.

    Third, yes, ScriptProcessorNode is deprecated, but there is still significant use. You can see this at https://www.chromestatus.com/metrics/feature/timeline/popularity/646. Compare that to https://www.chromestatus.com/metrics/feature/timeline/popularity/2263 for an AudioWorkletNode.

    Certainly, AudioWorklets are the way to go, but when I want something quick and dirty and don't mind processing on the main thread, I use a ScriptProcessorNode. But if I'm doing something that would be production quality, I'd try to use AudioWorkletNode instead.