6

我一直在互联网上寻找这个问题的答案,但我找不到任何资源。有谁知道如何使用 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
4

1 回答 1

1
AudioBuffer.getChannelData(channel_number);

您可以从AudioBuffer.numberOfChannels

编辑:
有关更多详细信息,您可以查看 MDN 文档中的AudioBuffergetChannelData方法。

于 2014-03-04T11:13:01.283 回答