有没有办法从一个音频文件得到类似分贝水平,这一信息转换为一个JSON阵列? [英] Is there a way get something like decibel levels from an audio file and transform that information into a json array?
问题描述
所以,我可以利用这些信息来协调像制作元素亮页动画作为分贝水平获得更高
So that I can use the information to coordinate a page animation like making elements brighter as the decibel levels get higher
推荐答案
这个方法将在Chrome / Safari上:的http:// jsbin.com/ixuyid/9/edit
This approach will work in Chrome / Safari: http://jsbin.com/ixuyid/9/edit
重要的东西在这里发生:
The important stuff happens here:
processor.onaudioprocess = function(evt){
var input = evt.inputBuffer.getChannelData(0)
, len = input.length
, total = i = 0
, rms
while ( i < len ) total += Math.abs( input[i++] )
rms = Math.sqrt( total / len )
meter.style.width = ( rms * 100 ) + '%'
}
基本上,你通过他们抢的原始PCM数据(值从-1到1)每2048个样本,你循环,计算超过给定时间段的平均信号电平。
Basically, you grab the raw PCM data (values from -1 to 1) every 2048 samples and you loop through them, calculating the average signal level over the given period of time.
您可以然后使用该值做你的动画。
You can then use that value to do your animations.
编辑:
更新为使用RMS,而贾森指出的是更有意义的测量。
Updated to use RMS, which as Jason pointed out is a more meaningful measurement.
这篇关于有没有办法从一个音频文件得到类似分贝水平,这一信息转换为一个JSON阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!