files/en-us/web/api/audioencoder/configure/index.md
{{securecontext_header}}{{APIRef("WebCodecs API")}}{{AvailableInWorkers("window_and_dedicated")}}
The configure() method of the {{domxref("AudioEncoder")}} interface enqueues a control message to configure the audio encoder for encoding chunks.
configure(config)
config
codec
sampleRate
numberOfChannels
bitrate {{optional_inline}}
bitrateMode {{optional_inline}}
: An enumerated value that defines the bitrate mode the encoder should use. Possible values are:
"constant"
"variable" (default)
Specific codec encoder implementations may use slightly different terminology (for example, CBR vs VBR for Opus), but they should all map to the general concept of "constant" versus "variable" bitrate.
opus {{optional_inline}}
OpusEncoderConfig object, the possible properties of which are as follows:
application {{optional_inline}}
audio (default)
lowdelay
voip
complexity {{optional_inline}}
format {{optional_inline}}
opus (default)
EncodedAudioChunks in Opus format. In this case, no metadata are necessary to decode the encoded audio stream.ogg
EncodedAudioChunks in Ogg format. In this case, no metadata are necessary to decode the encoded audio stream. In this case, the metadata of the encoded audio stream are provided in the decoder configuration — via the description property of the config object passed into {{domxref("AudioDecoder.configure()")}}.frameDuration {{optional_inline}}
EncodedAudioChunks outputted by the encoder. If not specified, frameDuration defaults to 20000.packetlossperc {{optional_inline}}
packetlossperc defaults to 0.signal {{optional_inline}}
auto (default)
music
voice
usedtx {{optional_inline}}
usedtx defaults to false.useinbandfec {{optional_inline}}
useinbandfec defaults to false.None ({{jsxref("undefined")}}).
config is invalid.InvalidStateError {{domxref("DOMException")}}
"closed".NotSupportedError {{domxref("DOMException")}}
config is valid but the user agent cannot provide a codec that can decode this profile.The following example creates a new {{domxref("AudioEncoder")}} and configures it with some of the available options.
const init = {
output: handleOutput,
error(e) {
console.log(e.message);
},
};
let config = {
codec: "mp3",
sampleRate: 44100,
numberOfChannels: 2,
bitrate: 128_000, // 128 kbps
bitrateMode: "constant",
};
let encoder = new AudioEncoder(init);
encoder.configure(config);
The following example creates a new {{domxref("AudioEncoder")}} and configures it with Opus-specific options.
const init = {
output: handleOutput,
error(e) {
console.log(e.message);
},
};
let opusConfig = {
application: "voip",
complexity: 9,
signal: "voice",
usedtx: true,
};
let config = {
codec: "opus",
sampleRate: 44100,
numberOfChannels: 2,
bitrate: 128_000,
opus: opusConfig,
};
let encoder = new AudioEncoder(init);
encoder.configure(config);
{{Specifications}}
{{Compat}}