Decode Ogg Opus audio to PCM samples with libopus WASM.
import decode, { decoder } from '@audio/decode-opus'
let { channelData, sampleRate } = await decode(opusBytes)
let dec = await decoder() // initialize WASM
let a = dec.decode(chunk1)
let b = dec.decode(chunk2)
let tail = dec.flush()
dec.free()
decoder() is asynchronous. Its decode() and flush() methods are synchronous. flush() ends the stream.
Metadata
Read OpusTags metadata and cover art without decoding audio:
import { parseMeta } from '@audio/decode-opus/meta'
let { meta, sampleRate } = parseMeta(opusBytes)
// meta: { title, artist, album, year, genre, ..., pictures }
License
ॐ · MIT. Bundled libopus is BSD 3-Clause. src/decode-opus.js bundles codec-parser, LGPL-3.0-or-later (LICENSE.codec-parser). The bundled codec-parser is version 2.5.0, and the last step of this repository's build.sh builds src/decode-opus.js from src/decode-opus.src.js with esbuild, so it can be rebuilt with a modified codec-parser; the GNU GPL that the LGPL-3.0 supplements is in LICENSE.gpl-3.0.