我一直在互联网上寻找这个问题的答案,但我找不到任何资源。有谁知道如何使用 JavaScript 将 AudioBuffer 对象转换为 ArrayBuffer?这是我目前的尝试
//Send audio data to websockets server
function callback(stream) {
var ws = new WebSocket("ws://localhost:8080");
ws.binaryType = 'arraybuffer';
var context = new webkitAudioContext();
var mediaStreamSource = context.createMediaStreamSource(stream);
console.log(mediaStreamSource);
var request = new XMLHttpRequest();
request.open('GET', 'http://s3.amazonaws.com/fldrMusic/01_-%20Fire%20Walker.mp3', true);
request.responseType = 'arraybuffer';
console.log("Current 'request.response' value");
console.log(request.response);
request.onload = function() {
context.decodeAudioData(request.response, function(buffer){
console.log("sent message");
console.log(buffer);
ws.send(buffer);
//Serialize javascript object
console.log("sent message encoded");
var buff = Base64Binary.decodeArrayBuffer(buffer.toString());
console.log(buff);
},
function(buffer){
alert("decode failed!");
})
}
request.send();
}//end 'callback' function