Deprecated: 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 compatibility table 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.
This event is not cancelable and does not bubble.
Also implements the properties inherited from its parent, Event
.
-
playbackTime
Read only
-
A double representing the time when the audio will be played, as defined by the time of AudioContext.currentTime
.
-
inputBuffer
Read only
-
An AudioBuffer
that is the buffer containing the input audio data to be processed. The number of channels is defined as a parameter numberOfInputChannels
, of the factory method AudioContext.createScriptProcessor()
. Note that the returned AudioBuffer
is only valid in the scope of the event handler.
-
outputBuffer
Read only
-
An AudioBuffer
that is the buffer where the output audio data should be written. The number of channels is defined as a parameter, numberOfOutputChannels
, of the factory method AudioContext.createScriptProcessor()
. Note that the returned AudioBuffer
is only valid in the scope of the event handler.
scriptNode.addEventListener("audioprocess", (audioProcessingEvent) => {
const inputBuffer = audioProcessingEvent.inputBuffer;
const outputBuffer = audioProcessingEvent.outputBuffer;
for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
const inputData = inputBuffer.getChannelData(channel);
const outputData = outputBuffer.getChannelData(channel);
for (let sample = 0; sample < inputBuffer.length; sample++) {
outputData[sample] = inputData[sample];
outputData[sample] += (Math.random() * 2 - 1) * 0.2;
}
}
});
You could also set up the event handler using the onaudioprocess
property:
scriptNode.onaudioprocess = (audioProcessingEvent) => {
};
Since the August 29, 2014, Web Audio API specification publication, this feature has been deprecated. It is no longer on track to become a standard.
It was replaced by AudioWorklets and the AudioWorkletNode
interface.