问题
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