gpt4 book ai didi

javascript - 尝试加载缓冲区时Recorder.js WebAudio API TypeError问题

转载 作者:行者123 更新时间:2023-12-03 01:59:19 25 4
gpt4 key购买 nike

我使用recorder.js来记录用户。然后,我尝试将录音的缓冲区发送到缓冲区列表,以便当我想一次播放所有声音时,该程序循环遍历缓冲区数组,并将它们变成源节点并进行播放。但是,它将引发TypeError。这是代码:

function layerRecording() {
var newBuffer;
rec.exportWAV(function(wav) {
var url = window.URL.createObjectURL(wav);
console.log(url);
var getSound = new XMLHttpRequest(); // Load the Sound with XMLHttpRequest
getSound.open("GET", url, true);
getSound.responseType = "arraybuffer"; // Read as Binary Data
getSound.onload = function() {
context.decodeAudioData(getSound.response, function(buffer){
newBuffer = buffer; // Decode the Audio Data and Store it in a Variable
});
buffers.push(newBuffer); //adds to the list of buffers
}
getSound.send(); // Send the Request and Load the File
});
}

//And then later on when I call this with buffers:
var playAll = function(bufferList) {
sourceList=[];
for (var i=0; i<bufferList.length;i++){
var currentSource = context.createBufferSource();
console.log(i);
currentSource.buffer = bufferList[i];
currentSource.connect(context.destination);
sourceList[i]=currentSource;
}
for (var i=0; i<sourceList.length;i++){
sourceList[i].start(0,startOffset);
}
}


我在录制的音频上遇到以下错误:
未捕获的TypeError:无法在“AudioBufferSourceNode”上设置“buffer”属性:提供的值不是“AudioBuffer”类型。

谢谢您的帮助

最佳答案

没关系,这是一个范围问题。只需将push语句移到encodeAudioData()内即可。哎呀

关于javascript - 尝试加载缓冲区时Recorder.js WebAudio API TypeError问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32938522/

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