AudioWorkletNode() 构造函数创建新 AudioWorkletNode object, which represents an AudioNode that uses a JavaScript function to perform custom audio processing.

句法

var node = new AudioWorkletNode(context, name);
var node = new AudioWorkletNode(context, name, options);
					

参数

context
BaseAudioContext instance this node will be associated with.
名称
A string, which represents the name of the AudioWorkletProcessor this node will be based on. A processor with the provided name must first be registered using the AudioWorkletGlobalScope.registerProcessor() 方法。
选项 可选
An object based on the AudioWorkletNodeOptions dictionary, which contains zero or more optional properties to configure the new node. The result of the structured clone algorithm applied to the object is also internally passed into the associated AudioWorkletProcessor() constructor — this allows custom initialization of an underlying user-defined AudioWorkletProcessor . Available properties are as follows:
numberOfInputs 可选
The value to initialize the numberOfInputs property to. Defaults to 1.
numberOfOutputs 可选
The value to initialize the numberOfOutputs property to. Defaults to 1.
outputChannelCount 可选
An array defining the number of channels for each output. For example, outputChannelCount: [n, m] specifies the number of channels in the first output to be n and the second output to be m . The array length must match numberOfOutputs .
parameterData 可选
An object containing the initial values of custom AudioParam objects on this node (in its 参数 property), with key being the name of a custom parameter and value being its initial value.
processorOptions 可选
Any additional data that can be used for custom initialization of the underlying AudioWorkletProcessor .

返回值

The newly constructed AudioWorkletNode 实例。

异常

NotSupportedError
指定 options.outputChannelCount is 0 or larger than the current implementation supports.
IndexSizeError
The length of options.outputChannelCount array does not match options.numberOfOutputs .

范例

For a complete example demonstrating user-defined audio processing, see the AudioWorkletNode 页面。

规范

规范 状态 注释
Web 音频 API
The definition of 'AudioWorkletNode()' 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
AudioWorkletNode() 构造函数 Chrome 66 Edge 79 Firefox 76 IE 不支持 No Opera ? Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android ? Safari iOS 不支持 No Samsung Internet Android 9.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: