BaseAudioContext.audioWorklet
property is not, thus custom
AudioWorkletProcessor
s cannot be defined outside them.
AudioWorkletNode
接口在
Web 音频 API
represents a base class for a user-defined
AudioNode
, which can be connected to an audio routing graph along with other nodes. It has an associated
AudioWorkletProcessor
, which does the actual audio processing in a Web Audio rendering thread.
AudioWorkletNode()
AudioWorkletNode
对象。
Also Inherits properties from its parent,
AudioNode
.
AudioWorkletNode.port
只读
MessagePort
used for bidirectional communication between the node and its associated
AudioWorkletProcessor
. The other end is available under the
port
property of the processor.
AudioWorkletNode.parameters
只读
AudioParamMap
— a collection of
AudioParam
objects. They are instantiated during the creation of the underlying
AudioWorkletProcessor
。若
AudioWorkletProcessor
has a static
parameterDescriptors
getter, the
AudioParamDescriptor
array returned from it is used to create
AudioParam
objects on the
AudioWorkletNode
. With this mechanism it is possible to make your own
AudioParam
objects accessible from your
AudioWorkletNode
. You can then use their values in the associated
AudioWorkletProcessor
.
AudioWorkletNode.onprocessorerror
AudioWorkletProcessor
. Once fired, the processor and consequently the node will output silence throughout its lifetime.
Also inherits methods from its parent,
AudioNode
.
AudioWorkletNode
interface does not define any methods of its own.
In this example we create a custom
AudioWorkletNode
that outputs white noise.
First, we need to define a custom
AudioWorkletProcessor
, which will output white noise, and register it. Note that this should be done in a separate file.
// white-noise-processor.js
class WhiteNoiseProcessor extends AudioWorkletProcessor {
process (inputs, outputs, parameters) {
const output = outputs[0]
output.forEach(channel => {
for (let i = 0; i < channel.length; i++) {
channel[i] = Math.random() * 2 - 1
}
})
return true
}
}
registerProcessor('white-noise-processor', WhiteNoiseProcessor)
Next, in our main script file we'll load the processor, create an instance of
AudioWorkletNode
passing it the name of the processor, and connect the node to an audio graph.
const audioContext = new AudioContext()
await audioContext.audioWorklet.addModule('white-noise-processor.js')
const whiteNoiseNode = new AudioWorkletNode(audioContext, 'white-noise-processor')
whiteNoiseNode.connect(audioContext.destination)
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'AudioWorkletNode' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioWorkletNode
|
Chrome 66 | Edge 79 | Firefox 76 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android 66 | Chrome Android 66 | Firefox Android 不支持 No | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android 9.0 |
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 |
onprocessorerror
|
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 |
参数
|
Chrome 66 | Edge 79 | Firefox 76 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android 66 | Chrome Android 66 | Firefox Android 不支持 No | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android 9.0 |
port
|
Chrome 66 | Edge 79 | Firefox 76 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android 66 | Chrome Android 66 | Firefox Android 不支持 No | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android 9.0 |
processorerror
event
|
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 |
完整支持
不支持
兼容性未知
AudioWorkletNode
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode