Question

I suspect the answer to this question is 'no', but just in case anyone has more info...

I'm processing audio and video and it appears that simply storing audio samples in an ScripProcessorNode's onaudioprocess handler (for later processing) is using up to 40% of CPU on lower end hardware. This is making my video processing miss frames.

I'd like to move the audio processing to a web worker but there doesn't seem to be any access to navigator.webkitGetUserMedia (or any variants) in a web worker context.

As I'm only storing the data at the moment and it's causing such an overhead, I think sending it in a message to the webworker would have a similar overhead.

In short, my question is: is there any way to access a microphone directly from a web worker?

Was it helpful?

Solution

Unfortunately the answer is no. Webworkers do not have (direct) access to userMedia. Depending on how you're processing the data, you could start in the main thread and use worker.postMessage to offload some work to the worker. However, whatever you pass to worker.postMessage has to be serializable - so it can't be the audio stream itself for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top