AudioEncoder.AudioEncoder()
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
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".
Syntax
new AudioEncoder(init);
Parameters
init-
An object containing two required callbacks.
output-
A callback which takes a
EncodedAudioChunkobject as the first argument, and an optional metadata object as the second. The metadata object has one member,decoderConfigwhich has an object as its value containing:codec-
A
stringcontaining a valid codec string. sampleRate-
An integer representing the number of frame samples per second.
numberOfChannels-
An integer representing the number of audio channels.
-
descriptionOptional -
A
BufferSourcecontaining a sequence of codec specific bytes, commonly known as extradata.
error-
A callback which takes an
Errorobject as its only argument.
Examples
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, });
Specifications
| Specification |
|---|
| WebCodecs # dom-audioencoder-audioencoder |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
AudioEncoder |
94 |
94 |
No |
No |
80 |
No |
94 |
94 |
No |
No |
No |
No |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioEncoder/AudioEncoder