gpt4 book ai didi

javascript - 将 AudioBuffer 转换为 ArrayBuffer

转载 作者:搜寻专家 更新时间:2023-11-01 04:37:28 30 4
gpt4 key购买 nike

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

最佳答案

AudioBuffer.getChannelData(channel_number);

您可以从AudioBuffer.numberOfChannels获取 channel 数

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

关于javascript - 将 AudioBuffer 转换为 ArrayBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18293611/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com