发布于 2014-06-26 11:00:38
使用OfflineAudioContext,这将给您一个PCM缓冲区,异步地返回。计算窗口的RMS值(或者只使用时间域,取决于您想要做什么),并将其放在一个或其他地方。
OfflineAudioContext允许您以机器运行的速度运行一个图形,并且是AudioContext的替代,除了三个不能使用的节点(MediaStreamAudioDestinationNode、MediaStreamSourceNode和MediaElementAudioSourceNode),因为MediaStream是实时对象:当没有实时呈现时,它们是没有意义的。
事情是这样的:
var off = new OfflineAudioContext(2 /* stereo */,
44100 /* length in frames */,
44100 /* samplerate */);
/* do your thing: setup your graph as usual */
off.createOscillator(...);
...
...
/* This is called when the graph has rendered one
* second of audio, here: 44100 frames at 44100 frames per second */
off.oncomplete = function(e) {
e.renderedBuffer; /* is an AudioBuffer that contains the PCM data */
};
/* kick off the rendering */
off.startRendering();
https://stackoverflow.com/questions/24435838
复制