大网数据广告活动
Web 标准与前端开发

AudioWorkletNode: AudioWorkletNode() constructor

· 52CE 我爱测

The **`AudioWorkletNode()`** constructor creates a new AudioWorkletNode object, which represents an AudioNode that uses a JavaScript function to perform custom audio processing.

Web Audio API

The AudioWorkletNode() constructor creates a new AudioWorkletNode object, which represents an AudioNode that uses a JavaScript function to perform custom audio processing.

Syntax

new AudioWorkletNode(context, name)
new AudioWorkletNode(context, name, options)

Parameters

  • context
    • : The BaseAudioContext instance this node will be associated with.
  • name
    • : 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() method.
  • options
    • : An object containing zero or more of the following optional properties to configure the new node:

      [!NOTE] The result of the structured clone algorithm applied to the object is also internally passed into the associated AudioWorkletProcessor.AudioWorkletProcessor constructor — this allows custom initialization of an underlying user-defined AudioWorkletProcessor.

      • numberOfInputs
        • : The value to initialize the AudioNode.numberOfInputs property to. Defaults to 1.
      • numberOfOutputs
        • : The value to initialize the AudioNode.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 AudioWorkletNode.parameters 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.

Exceptions

  • NotSupportedError DOMException

    • : The specified options.outputChannelCount is 0 or larger than the current implementation supports.

      Both options.numberOfInputs and options.numberOfOutputs are 0.

  • IndexSizeError DOMException

    • : The length of options.outputChannelCount array does not match options.numberOfOutputs.

Usage notes

Different options parameter values can have the following effects.

If the number of inputs and number of outputs are both set to 0, a NotSupportedError will be thrown and the node construction process aborted. If the length of the outputChannelCount array doesn't match numberOfOutputs, an IndexSizeError DOMException will be thrown.

If outputChannelCount isn't specified, and numberOfInputs and numberOfOutputs are both 1, the AudioWorkletNode's initial channel count is set to 1. This has the effect of changing the output channel count to dynamically change to the computed number of channels, based on the input's channel count and the current setting of the AudioNode property AudioNode.channelCountMode.

Otherwise, if outputChannelCount is provided and if the values of numberOfInputs and numberOfOutputs are both 1, the audio worklet node's channel count is set to the value of outputChannelCount. Otherwise, the channel count of each channel in the set of output channels is set to match the corresponding value in the outputChannelCount array.

Examples

For a complete example demonstrating user-defined audio processing, see the AudioWorkletNode page.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。