javascript - 在 Web Audio API 中导出音频强度

标签 javascript audio html5-audio web-audio-api

我正在尝试使用 Web Audio API 查找音频时刻的强度。我在规范中找到的唯一与强度相关的是:

analyser.minDecibels
analyser.maxDecibels

有办法吗?

最佳答案

如果我没理解错的话,你想要一个在声音大的时候高,在声音小的时候低的数字。您可以为此使用“声压级”。

从 Web Audio API 获取这个数字非常简单,您猜对了我们将使用 AnalyserNode 来实现这一点。这是一个示例代码,向您展示了如何执行此操作:

var ac = new AudioContext();
/* create the Web Audio graph, let's assume we have sound coming out of the
 * node `source` */
var an = ac.createAnalyser();
source.connect(an);
/* Get an array that will hold our values */
var buffer = new Uint8Array(an.fftSize);

function f() {
  /* note that getFloatTimeDomainData will be available in the near future,
   * if needed. */
  an.getByteTimeDomainData(buffer);
  /* RMS stands for Root Mean Square, basically the root square of the
  * average of the square of each value. */
  var rms = 0;
  for (var i = 0; i < buffer.length; i++) {
    rms += buffer[i] * buffer[i];
  }
  rms /= buffer.length;
  rms = Math.sqrt(rms);
  /* rms now has the value we want. */
  requestAnimationFrame(f);
}

requestAnimationFrame(f);
/* start our hypothetical source. */
source.start(0);

关于javascript - 在 Web Audio API 中导出音频强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22104036/

相关文章:

javascript - 页面加载时出现弹出窗口

ruby - FFMPEG:在带有可选音轨的视频上覆盖 PNG

jquery - 使用jquery动态选择音频文件加载到HTML5播放器中

streaming - 通过客户端 XHR 打开 Soundcloud Track 的 stream_url?

javascript - Jquery Slide 弄乱了其他的 div

javascript - 调用 JavaScript 函数时如何阻止网页滚动到顶部?

javascript - (VueJS) Vuex getter 应该根据另一个模块状态变化进行更新

audio - 仅使用RED5流音频

javascript - 如何使用 Javascript 将多个音频文件附加到当前正在播放的音频中?

javascript - 使用jquery点击图像按钮时控制音频播放器