弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The audioprocess event of the ScriptProcessorNode interface is fired when an input buffer of a script processor is ready to be processed.

冒泡 No
可取消 No
Default action None
接口 AudioProcessingEvent
事件处理程序特性 ScriptProcessorNode.onaudioprocess

范例

scriptNode.addEventListener('audioprocess', function(audioProcessingEvent) {
  // The input buffer is a song we loaded earlier
  var inputBuffer = audioProcessingEvent.inputBuffer;
  // The output buffer contains the samples that will be modified and played
  var outputBuffer = audioProcessingEvent.outputBuffer;
  // Loop through the output channels (in this case there is only one)
  for (var channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
    var inputData = inputBuffer.getChannelData(channel);
    var outputData = outputBuffer.getChannelData(channel);
    // Loop through the 4096 samples
    for (var sample = 0; sample < inputBuffer.length; sample++) {
      // make output equal to the same as the input
      outputData[sample] = inputData[sample];
      // add noise to each output sample
      outputData[sample] += ((Math.random() * 2) - 1) * 0.2;
    }
  }
})
					

You could also set up the event handler using the ScriptProcessorNode.onaudioprocess 特性:

scriptNode.onaudioprocess = function(audioProcessingEvent) {
  ...
}
					

规范

规范 状态 注释
Web 音频 API
The definition of 'AudioProcessingEvent' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
audioprocess event 弃用 Chrome 14 Prefixed
14 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 25 IE No Opera 22
22
15 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 6 Prefixed
6 Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android Yes Chrome Android Yes Firefox Android 25 Opera Android 22
22
14 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 6 Prefixed
6 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

弃用。不要用于新网站。

弃用。不要用于新网站。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: