Using Web Audio API decodeAudioData with external binary data

半城伤御伤魂 提交于 2019-12-06 11:49:04

Without the container, I'm not sure how decodeAudioData would know that it's an MP3. Or what the bitrate is. Or how many channels it has. Or a lot of other pretty important information. Basically, you need to tell decodeAudioData how to interpret that ArrayBuffer.

The only thing I could think of on the client side is trying to use a Blob. You'd basically have to write the header yourself, and then readAsArrayBuffer before passing it in to decodeAudioData.

If you're interested in trying that out, here's a spec: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm

And here's RecorderJS, which would show you how to create the Blob (although it writes RIFF/WAV headers instead of MP3):

https://github.com/mattdiamond/Recorderjs/blob/master/recorderWorker.js

You'd want to look at the encodeWAV method.

Anyway, I would strongly recommend getting this sorted out on the server instead, if you can.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!