gpt4 book ai didi

javascript - Chrome 中收到 "decodeAudioData error null"

转载 作者:行者123 更新时间:2023-11-28 08:19:13 26 4
gpt4 key购买 nike

网络音频开发人员您好,

我在 Chrome 中收到“decodeAudioData error null”和Firebug 中的“decodeAudioData 错误未定义”。

Firebug 还说“传递给decodeAudioData的缓冲区包含未知的内容类型。”

这段代码有问题吗?还有什么事情需要与“网络音频 API”?

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Together 2 </title>
</head>
<body>
<script type="text/javascript">
window.onload = init;
var context;
var bufferLoader;
function init() {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
bufferLoader = new BufferLoader(context,
[ '../web-audio/path/chrono.mp3' ],
finishedLoading
);
bufferLoader.load();
}

function finishedLoading(bufferList) {
var source1 = context.createBufferSource();
source1.buffer = bufferList[0];
source1.connect(context.destination);
source1.start(0);
}

function BufferLoader(context, urlList, callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
}
BufferLoader.prototype.loadBuffer = function(url, index) { // Load buffer asynchronously
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
var loader = this;
request.onload = function() {
// Asynchronously decode the audio file data in request.response
loader.context.decodeAudioData(
request.response,
function(buffer) {
if (!buffer) {
alert('error decoding file data: ' + url);
return;
}
loader.bufferList[index] = buffer;
if (++loader.loadCount == loader.urlList.length)
loader.onload(loader.bufferList);
},
function(error) {
console.error('decodeAudioData error', error);
}
);
}
request.onerror = function() {
alert('BufferLoader: XHR error');
}
request.send();
}

BufferLoader.prototype.load = function() {
for (var i = 0; i < this.urlList.length; ++i)
this.loadBuffer(this.urlList[i], i);
}
</script>
</body>
</html>

最佳答案

我遇到了同样的问题,这取决于 wav 文件本身使用的编解码器类型。仅支持 PCM,而引发错误的文件是 MS-ADPCM。您可以使用 QuickTime 或 VLC 获取编解码器信息,并在必要时将其转换为 PCM。

我想您的 MP3 也有类似的问题。

关于javascript - Chrome 中收到 "decodeAudioData error null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23203464/

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