The docs give an option to load an audio file from a url (ex: wavesurfer.load('audio.mp3'),
but I currently have a Float32Array holding the raw audio data. Is there a way to load from that?
I tried making a Blob of the array and using loadBlob:
var blob = new Blob([arr], {type: 'audio/wav' });
wavesurfer.loadBlob(blob);
and I keep getting this error: "Uncaught (in promise) DOMException: Unable to decode audio data"
I've tried also variants such as createObjectURL from the Blob. Admittedly, I am relatively new to this stuff, so if it's just some simple syntax error, I would love an example of loading to wavesurfer from a float array. I tried looking in some of the example source code and wavesurfer's code, but I can't figure it out! Any help is appreciated.
Maybe this helps: https://stackoverflow.com/a/31360448/5097199
Hi,
Maybe not, since I wasn't looking to pass it in through a file at all.
But I've found a solution if anyone needs this in the future:
I used https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js, Matt Diamond's recorder.js project, namely the encodeWAV function that returns a DataView (and the writeString and floatTo16BitPCM functions that help encodeWAV), then made a Blob from that DataView.
I'd also like to draw a waveform from an already decoded Float32Array of samples. I might have misunderstood the above solution, but re-encoding the data so that it can then be decoded again by wavesurfer is a big waste of resources and not an acceptable solution for me. I'd love to just be able to just give wavesurfer an array of samples and a sample rate, or an already filled AudioBuffer and have it do its thing.
A use case for this would be doing some processing on some audio and then wanting to draw the processed audio before saving to a file. No sense in saving and reloading when you could go direct.
Load an AudioBuffer like this:
wavesurfer.loadDecodedBuffer(audioBuffer);
and an ArrayBuffer:
wavesurfer.loadArrayBuffer(arrayBuffer);
Most helpful comment
Load an AudioBuffer like this:
wavesurfer.loadDecodedBuffer(audioBuffer);and an ArrayBuffer:
wavesurfer.loadArrayBuffer(arrayBuffer);