magenta / magenta-js

Magenta.js: Music and Art Generation with Machine Learning in the browser
https://magenta.tensorflow.org
Apache License 2.0
1.96k stars 311 forks source link

OfflineAudioContext not defined in web worker #483

Open cannoneyed opened 4 years ago

cannoneyed commented 4 years ago

When importing / using certain pieces of Magenta functionality in a web worker (namely anything that uses audio_utils, such as Transcription or GANSynth), OfflineAudioContext doesn't exist and the browser-detecting code throws an error

https://github.com/magenta/magenta-js/blob/master/music/src/core/audio_utils.ts#L36-L39

Obviously, it doesn't make sense to use these models in a web worker without the AudioContext, but it is possible to import the audio_utils code through some other dependency trees (which I wasn't able to fully suss out)

notwaldorf commented 4 years ago

I would probably as a first step throw a clear error earlier in audio_utils. Something like "super sorry, this model does not work in node or a web worker because OfflineAudioContext"

The second step is kind of a pain, and like you said get a third party polyfill for OfflineAudioContext and do a similar dance like you did for fetch/performance.

notwaldorf commented 3 years ago

@cannoneyed what's the status of this? You did a bit of work around it, is it ready to be closed?