gpt4 book ai didi

javascript - 为什么不同操作系统上的decodeAudioData()结果不同

转载 作者:行者123 更新时间:2023-11-28 18:52:47 27 4
gpt4 key购买 nike

更新 2:在此处运行脚本。单击“LOAD”按钮时会显示采样率。

function decode() {
// If the default naming is not enabled, use the Chrome one
if (!window.AudioContext) {
if (!window.webkitAudioContext) {
alert("No AudioContext found.");
}
window.AudioContext = window.webkitAudioContext;
}
var audioContext = new AudioContext();
alert("sample rate: " + audioContext.sampleRate);
var sourceNode;

var BUFFER_SIZE = 1024;

// Create buffer node and download file to buffer
createAudioNodes();
var fileURL = "http://plaay.in/decode-audio-data/decode-this-audio.wav";
downloadAudioFromURL(fileURL);

function createAudioNodes() {
sourceNode = audioContext.createBufferSource();
sourceNode.connect(audioContext.destination);
}

function downloadAudioFromURL(url) {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.addEventListener("progress", updateProgress);

request.onload = function() {
audioContext.decodeAudioData(request.response, function(buffer) {
setSourceBuffer(buffer);
}, onError);
};
request.send();
}

function updateProgress(progress) {
if (progress.lengthComputable) {
var percentComplete = Math.round(progress.loaded / progress.total * 100);
document.getElementById("progress").innerHTML = "Loading... " + percentComplete.toString() + "%";
}
}

function setSourceBuffer(buffer) {
var leftInBuffer = buffer.getChannelData(0);
console.log("leftInBuffer length: " + leftInBuffer.length);
for (var i = 0; i < leftInBuffer.length; i++) {
console.log(leftInBuffer[i]);
}
}

function onError(e) {
console.log(e);
}
}
<!doctype html>
<html lang="en-US">

<head>
<meta charset="utf-8">
<title>Decode Audio Data</title>
</head>

<body>
<script src="decode.js"></script>
<button id="playButton" type="button" style="height:40px;width:150px" onclick="decode()">LOAD</button>
<p id="progress">File download progress</p>
</body>

</html>

更新:提交问题 here .

我想解码音频文件并获取其原始数据以便在下一步中进行处理。这个想法是使用 decodeAudioData()网络音频 API。奇怪的问题是解码结果将取决于操作系统。有没有人遇到过同样的问题,或者知道原因吗?

我快速做了一个demo并在Mac OS(10.11)和Windows 7上进行了测试,浏览器均为Chrome(v46.0+),但结果不同。可视化结果:

enter image description here

每个人都可以运行这个demo ,只需单击“LOAD”按钮,结果就会记录在控制台中。

最佳答案

Windows 和 Chrome 之间的它们不应该有所不同。在 crbug.com/new 提交错误.

关于javascript - 为什么不同操作系统上的decodeAudioData()结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34201957/

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