I made a proof of concept on how to create an audio application in the browser using Rust and WebAssembly. More of an example than a tutorial, but I wrote some paragraphs in the README about the faced challenges.
Quoting main page:
Needs Chromium/Chrome 74+ and chrome://flags/#enable-experimental-web-platform-features enabled!
What experimental flags do you need & is there a way to drop it? I’m interested in adding audio to a web app, but there’s no way I can ask all users to turn on some flag in their browser.
Hej, thanks for your interest !
You’ve got the flag (
#enable-experimental-web-platform-features) right there, just copy&paste the complete URL to the browser address and it’ll bring you right to it.
Unfortunately it’s not allowed to link to
chrome:// URLs from a remote page.
The module workers (that is, web workers that allow you to load a module directly) are still experimental, currently. I’m hoping they’ll become default soon, just as I’m hoping that the AudioWorklet will become available on Firefox.
That being said, depending on how complex the audio features are that you want to add to your web app (i.e., just play some sounds in the background), you might want to look into the WebAudio API to use it directly.
I agree that I can easily turn it on for my browser; but the problem is that if I ask all my app users to turn on the flag, I’m going to lose a significant chunk of them.
Totally, that’d be an unnecessary hurdle in production software.
You potentially could avoid using the flag by using a regular web worker, fetching the module in the main thread and posting it to the worker in a way similar to the AudioWorklet.
But if it’s a webapp that’s supposed to run in other browsers as well, you’d need to find some workaround/shim/polyfill for the AudioWorklet as well.
I guess my little prototype is far from being called production-ready.