我有一个获取音频的脚本。我想把这个频率与歌曲的确切时间联系起来。我可以获得webkitAudioContext currentTime属性,但这不准确,因为它在开始播放歌曲之前将声音保存在缓冲区中时开始计算时间。 这是我的代码:网络音频Api:与经过时间相关的频率
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);
}
}
谢谢!