rochars / wavefile

Create, read and write wav files according to the specs. :star: :notes: :heart:
MIT License
226 stars 48 forks source link

In Firefox and Safari => Error: Not a supported format #19

Closed gauravmak closed 4 years ago

gauravmak commented 4 years ago

Thanks for the great tool. I am using it to read the selected wave file before uploading it. It works well in Chrome but not in Firefox and Safari. Following is the code snippet.

const wav = new WaveFile();
var reader = new FileReader();
reader.readAsDataURL(file);

reader.onload = function() {
    wav.fromDataURI(reader.result);
    //...
}

Upon checking, I found that the container value is a blank string in Firefox while 'RIFF' in Chrome.

this.container = this.readString(buffer, 4);

if (this.supported_containers.indexOf(this.container) === -1) {
  throw Error('Not a supported format.');
}

PS - I hope you are safe and healthy in these crazy times.

rochars commented 4 years ago

I could not reproduce the problem. Hope you have found a solution.

Unfortunately, I am not able to work on this software at the moment - the code will remain public for anyone interested in continuing to work with this library, as well as anyone interested in developing and releasing new versions of it.

Thanks a lot for your concern. I hope you are well, too. :)

gauravmak commented 4 years ago

We ended up using SoXI (backend) to extract WAV files data. Hopefully, newer versions of browsers may have rectified the issue.

Thanks for the reply and all the best.

coraxx commented 4 months ago

I just had the same problem. Turns out for me, Safari was loading the file as "data:audio/x-wav;". Changing it to "data:audio/wav;" fixed it for me!

// read as data url
var reader = new FileReader();
reader.addEventListener(
    "load",
    () => {
        var inputUrl = reader.result;
        // Safari fix: file is loaded as "data:audio/x-wav;" -> change to "data:audio/wav;"
        if (inputUrl[11] === 'x') {
            inputUrl = inputUrl.slice(0,11) + inputUrl.slice(13,inputUrl.length);
        }
        wav.fromDataURI(inputUrl);

        // ... do stuff
},
false,
);
// Getting file from bootstrap form
reader.readAsDataURL($('#input-b1')[0].files[0]);

Hope this helps someone.