Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Dedicated Web Workers.
The AudioEncoder() constructor creates a new AudioEncoder object with the provided init.output callback assigned as the output callback, the provided init.error callback as the error callback, and the AudioEncoder.state set to "unconfigured".
new AudioEncoder(init)initAn object containing two required callbacks.
outputA callback which takes an EncodedAudioChunk object as the first argument, and an optional metadata object as the second. The metadata object has one member, decoderConfig which has an object as its value containing:
codecA string containing a valid codec string.
sampleRateAn integer representing the number of frame samples per second.
numberOfChannelsAn integer representing the number of audio channels.
description OptionalAn ArrayBuffer, a TypedArray, or a DataView containing a sequence of codec specific bytes, commonly known as extradata.
errorA callback which takes an Error object as its only argument.
In the following example an AudioEncoder is created with the two required callback functions, one to deal with the decoded frame and the other to handle errors.
const audioEncoder = new AudioEncoder({
output: processAudio,
error: onEncoderError,
});