我有一个获取音频的脚本。我想将该频率与歌曲的确切时间联系起来。我可以获取 webkitAudioContext currentTime 属性,但这并不准确,因为它在歌曲开始之前将声音保存在缓冲区中时开始计算时间。这是我的代码:
var context = new webkitAudioContext();
...
function drawSpectrogram(array) {
// copy the current canvas onto the temp canvas
var canvas = document.getElementById("canvas");
tempCtx.drawImage(canvas, 0, 0, 800, 512);
// iterate over the elements from the array
for (var i = 0; i < array.length; i++) {
// draw each pixel with the specific color
var value = array[i];
frequency = frequency + value + ";";
time = time + Math.round((context.currentTime) * 1000000) / 1000000 + ";";
ctx.fillStyle = hot.getColor(value).hex();
// draw the line at the right side of the canvas
ctx.fillRect(800 - 1, 512 - i, 1, 1);
}
}
谢谢!