--- title: ScriptProcessorNode slug: Web/API/ScriptProcessorNode translation_of: Web/API/ScriptProcessorNode ---

{{APIRef("Web Audio API")}}

注意:这个特性在2014年8月29日发布的Web Audio API规范中已经标记为不推荐,将很快会被Audio Workers代替.

ScriptProcessorNode 接口允许使用JavaScript生成、处理、分析音频. 它是一个 {{domxref("AudioNode")}}, 连接着两个缓冲区音频处理模块, 其中一个缓冲区包含输入音频数据,另外一个包含处理后的输出音频数据. 实现了 {{domxref("AudioProcessingEvent")}} 接口的一个事件,每当输入缓冲区有新的数据时,事件将被发送到该对象,并且事件将在数据填充到输出缓冲区后结束.

The ScriptProcessorNode stores the input in a buffer, send the audioprocess event. The EventHandler takes the input buffer and fill the output buffer which is sent to the output by the ScriptProcessorNode.

输入和输出缓冲区大小在创建时定义, 当 {{domxref("AudioContext.createScriptProcessor()")}} 方法被调用时 (都是由 {{domxref("AudioContext.createScriptProcessor()")}}的 bufferSize 参数定义). 缓冲区大小必须是在 256 到 16384 之间的 2 的次幂, 为 256, 512, 1024, 2048, 4096, 8192 或者 16384. Small numbers lower the latency, but large number may be necessary to avoid audio breakup and glitches.

If the buffer size is not defined, which is recommended, the browser will pick one that its heuristic deems appropriate.

Number of inputs 1
Number of outputs 1
Channel count mode "max"
Channel count 2 (not used in the default count mode)
Channel interpretation "speakers"

属性

从上一级继承属性, {{domxref("AudioNode")}}.

{{domxref("ScriptProcessorNode.bufferSize")}} {{readonlyInline}}
返回一个表示输入和输出缓冲区大小的整数. 它的值可以是在25616384 之间的 2 的次幂.

事件句柄

{{domxref("ScriptProcessorNode.onaudioprocess")}}
Represents the {{event("Event_handlers", "event handler")}} to be called.

方法

No specific methods; inherits methods from its parent, {{domxref("AudioNode")}}.

示例

{{page("/en-US/docs/Web/API/AudioContext.createScriptProcessor","Example")}}

Specifications

Specification Status Comment
{{SpecName('Web Audio API', '#the-scriptprocessornode-interface---deprecated', 'ScriptProcessorNode')}} {{Spec2('Web Audio API')}}  

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 {{property_prefix("webkit")}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(25)}} {{CompatNo}} 15 {{property_prefix("webkit")}}
22 (unprefixed)
6 {{property_prefix("webkit")}}
Feature Android Chrome Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} 28 {{property_prefix("webkit")}} {{CompatVersionUnknown}} {{CompatGeckoMobile(25)}} 1.2 {{CompatNo}} {{CompatNo}} 6 {{property_prefix("webkit")}}

See also