Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/api/audioencoder/configure/index.md
6529 views
---
title: AudioEncoder.configure() slug: Web/API/AudioEncoder/configure page-type: web-api-instance-method status: - experimental browser-compat: api.AudioEncoder.configure
---

{{securecontext_header}}{{APIRef("WebCodecs API")}}{{SeeCompatTable}}

The configure() method of the {{domxref("AudioEncoder")}} interface enqueues a control message to configure the audio encoder for encoding chunks.

Syntax

configure(config)

Parameters

  • config

    • : A dictionary object containing the following members:

      • codec

      • sampleRate

        • : An integer representing the number of frame samples per second.

      • numberOfChannels

        • : An integer representing the number of audio channels.

      • bitrate {{optional_inline}}

        • : An integer representing the bitrate.

Return value

None ({{jsxref("undefined")}}).

Exceptions

  • {{jsxref("TypeError")}}

    • : Thrown if the provided config is invalid.

  • InvalidStateError {{domxref("DOMException")}}

    • : Thrown if the {{domxref("AudioEncoder.state","state")}} is "closed".

  • NotSupportedError {{domxref("DOMException")}}

    • : Thrown if the provided config is valid but the user agent cannot provide a codec that can decode this profile.

Examples

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: "opus", sampleRate: 44100, numberOfChannels: 2, bitrate: 128_000, // 128 kbps }; let encoder = new AudioEncoder(init); encoder.configure(config);

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}