Usage in a service worker?
This library is amazing! However, when it's processing it locks up the UI so animations stop and buttons are not clickable.
I was wondering if I could put this in a service worker and am not sure if that has been done before.
The first problem is that a service worker can't import files and I can't figure out how to have my service worker use files in node_modules. I'm guessing I'll need a build step.
I was wondering if there were already a build option in this library for being able to load it the using a single <script> tag, because I think I'd be able to use that in my service worker. I didn't see that.
So I think I might need to write that, which I'll try to do but I'm not sure if I can.
Also I'm not sure if that will even work since there are two other files that get loaded in (the bin and the json files) and I'm not sure if that will work inside the service worker.
Any pointers you can give while I flail away at this would be appreciated.
Thanks!
I think it should work. On basicpitch.io, we have basicpitch run in an async function on file load.
Regarding using it in a
Thanks. It looks like I need to call importScripts instead of require and I need to serve the files from the same domain so I think I do need to create a build step for this. Still investigating...
For my immediate purposes, I just needed noteFramesToTime, addPitchBendsToNoteEvents, and outputToNotesPoly so I didn't need the whole tensor flow to work in the service worker. I copied over toMidi.js from the cjs build and Midi.js from the @tonejs dependency and just had to tweak a couple lines. I'm sure there is a cleaner way to do this, but so far it seems to work ok.
I have a feeling there might be some more complications when I try to put the BasicPitch class in a service worker but I don't immediately need that.