我在互联网上寻找答案,但是没有找到任何资源。有人知道如何使用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