Opus
Defined in: packages/voice/src/libopus.ts:132
Lunibee’s Opus encoder and decoder for 48 kHz stereo, on the system’s
libopus through bun:ffi: native speed with nothing to compile. Frees its
native state on destroy() (and, as a safety net, when it is collected).
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Opus(
application?):Opus
Defined in: packages/voice/src/libopus.ts:148
Parameters
Section titled “Parameters”application?
Section titled “application?”OpusApplication = OpusApplication.Audio
Returns
Section titled “Returns”Opus
Throws
Section titled “Throws”When libopus is not installed or refuses the settings.
Accessors
Section titled “Accessors”libraryPath
Section titled “libraryPath”Get Signature
Section titled “Get Signature”get
staticlibraryPath():string
Defined in: packages/voice/src/libopus.ts:179
Where libopus was loaded from.
Returns
Section titled “Returns”string
Methods
Section titled “Methods”decode()
Section titled “decode()”decode(
packet):Uint8Array
Defined in: packages/voice/src/libopus.ts:218
Decodes one Opus packet to s16le PCM (3,840 bytes for a 20 ms packet). An empty packet stands for a lost one and is concealed.
Parameters
Section titled “Parameters”packet
Section titled “packet”Uint8Array
Returns
Section titled “Returns”Uint8Array
Throws
Section titled “Throws”After destroy(), or for a corrupt packet.
destroy()
Section titled “destroy()”destroy():
void
Defined in: packages/voice/src/libopus.ts:244
Frees the native encoder and decoder. Safe to call twice.
Returns
Section titled “Returns”void
encode()
Section titled “encode()”encode(
pcm):Uint8Array
Defined in: packages/voice/src/libopus.ts:188
Encodes one 20 ms frame: 960 stereo samples of s16le PCM (3,840 bytes).
Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”Uint8Array
The Opus packet (a new array).
Throws
Section titled “Throws”After destroy(), for a frame of the wrong size, or when libopus fails.