Understanding AudioBuffer to ArrayBuffer conversion

早过忘川 提交于 2021-01-27 14:42:12

问题


I have an AudioBuffer client-side that I'd like to AJAX to a express server.

This link shows how a XMLHttpRequest can send/receive binary data - ArrayBuffer.

An ArrayBuffer is different to an AudioBuffer (or so I believe) as I decoded an ArrayBuffer to make the AudioBuffer in the first place. This was done using decodeAudioData() as part of the Web Audio API.

So my question is, can I convert an AudioBuffer back to an ArrayBuffer?

If this is possible, I'd like to then send the ArrayBuffer to my express server and then forward it on to a S3 bucket as shown in this example.

In that example, the code PUTs a Buffer in a S3 bucket created via a fs.readFileSync(). I assume the difference between a Buffer and ArrayBuffer wont be an issue with S3 :S


回答1:


Use the copyFromChannel method, then convert the Float32Array to an ArrayBuffer.

var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);  
var anotherArray = new Float32Array();
myArrayBuffer.copyFromChannel(anotherArray,1,0);


来源:https://stackoverflow.com/questions/40118921/understanding-audiobuffer-to-arraybuffer-conversion

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