opus-decoder
opus-decoder
is a Web Assembly Opus audio decoder.
See the homepage of this repository for more Web Assembly audio decoders like this one.
Installing
Install via NPM.
Usage
-
Create a new instance and wait for the WASM to finish compiling.
import {OpusDecoder} from 'opus-decoder';
const decoder = new OpusDecoder();
await decoder.ready;
-
Begin decoding Opus frames.
const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrame(opusFrame);
const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrames(opusFrameArray);
-
When done decoding, free up the memory being used by the WASM module. You will need to create a new instance to start decoding again.
decoder.free();
API
Getters
decoder.ready
- Returns a promise that is resolved when the WASM is compiled and ready to use.
Methods
Each method returns an object containing the decoded audio, number of samples decoded, and sample rate of the decoded audio.
The channelData
contains the raw decoded PCM for each channel (left, and right). Each Float32Array can be used directly in the WebAudio api.
{
channelData: [leftAudio, rightAudio],
samplesDecoded: 1234,
sampleRate: 48000
}
decoder.decodeFrame(opusFrame)
opusFrame
Uint8Array containing a single Opus frame.
decoder.decodeFrames(opusFrames)
opusFrames
Array of Uint8Arrays containing Opus frames.