Skip to content
Abstract class

CustomAudioEncoder

Base class for custom audio encoders. To add your own custom audio encoder, extend this class, implement the abstract methods and static supports method, and register the encoder using registerEncoder.

Used by

Static methods

supports()

ts
static supports(
	codec: AudioCodec,
	config: AudioEncoderConfig,
): boolean;

Returns true if and only if the encoder can encode the given codec configuration.

See AudioCodec.

Properties

codec

ts
readonly codec: AudioCodec;

The codec with which to encode the audio.

See AudioCodec.

config

ts
readonly config: AudioEncoderConfig;

Config for the encoder.

Events

onPacket

ts
readonly onPacket: (packet: EncodedPacket, meta?: EncodedAudioChunkMetadata) => unknown;

The callback to call when an EncodedPacket is available.

See EncodedPacket.

Methods

init()

ts
init(): MaybePromise<void>;

Called after encoder creation; can be used for custom initialization logic.

See MaybePromise.

encode()

ts
encode(
	audioSample: AudioSample,
): MaybePromise<void>;

Encodes the provided audio sample.

See AudioSample and MaybePromise.

flush()

ts
flush(): MaybePromise<void>;

Encodes all remaining audio samples and then resolves.

See MaybePromise.

close()

ts
close(): MaybePromise<void>;

Called when the encoder is no longer needed and its resources can be freed.

See MaybePromise.

Released under the Mozilla Public License 2.0.