gpt4 book ai didi

audio - 网络音频 API : decodeAudioData doesn't decode opus in Chrome

转载 作者:行者123 更新时间:2023-12-02 01:49:21 26 4
gpt4 key购买 nike

我目前正在尝试使 Opus 数据包与 Web Audio API 一起工作。然而,问题是,虽然 FireFox 和 Chrome 应该原生支持它,但只有 FireFox 可以使用 Web Audio API 中的 decodeAudioData 解码 OPUS 样本流。当我将 opus 文件拖到浏览器中时,Chrome 确实可以识别该文件,并且它也可以播放它!所以我想知道我可能在这里做错了什么导致 Chrome 失败。

然后我使用了来自 http://awm.jp/~yoya/js/audio/meow.html 的一些示例代码只需加载一个 opus 文件并尝试对其进行解码。同样,Firefox 会,而 Chrome 不会。所以我想知道是否有人可以证实我的发现或告诉我我在这里做错了什么。以下是早期链接的修改版本。谢谢!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<title> decodeAudioData sample </title>
</head>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
//$(document).ready(function() {
var catMeowingBuffer = null;
window.AudioContext = window.AudioContext||window.webkitAudioContext;
var context = new AudioContext();

function onError(err) {
console.log("unable to decode");
}

function loadCatSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';

// Decode asynchronously
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
catMeowingBuffer = buffer;
var src = context.createBufferSource();
src.buffer = catMeowingBuffer
src.connect(context.destination);
src.start(0);
}, onError);
}
request.send();
}

loadCatSound("opus.opus");

function playCatSound() {
if (catMeowingBuffer !== null) {
var src = context.createBufferSource();
src.buffer = catMeowingBuffer
src.connect(context.destination);
src.start(0);
}
}
//});
</script>

<body>
<h1> decodeAudioData sample </h1>


<button onclick="playCatSound();"> playCatSound </button>

<hr>
<address></address>
</body> </html>

最佳答案

这是 Chrome 中的错误。参见 https://code.google.com/p/chromium/issues/detail?id=409402 .

关于audio - 网络音频 API : decodeAudioData doesn't decode opus in Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23812810/

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