npm.io
1.4.0 • Published 2 weeks ago

@audio/decode-wma

Licence
LGPL-2.1-or-later
Version
1.4.0
Deps
0
Size
510 kB
Vulns
0
Weekly
0
Stars
209

@audio/decode-wma

Decode WMA audio to PCM float samples. The package combines a pure-JS ASF demuxer with FFmpeg's WMA decoders (wmav1, wmav2, wmapro, wmalossless), a slim LGPL-2.1-or-later libavcodec build compiled to WASM. Output matches FFmpeg's to float precision.

Install

npm i @audio/decode-wma

Usage

import decode from '@audio/decode-wma'

let { channelData, sampleRate } = await decode(wmaBuffer)
Streaming
import { decoder } from '@audio/decode-wma'

let dec = await decoder()
let result = dec.decode(chunk)
dec.free()

decoder() is asynchronous. Its decode() and flush() methods are synchronous.

ASF demuxer only
import { demuxASF } from '@audio/decode-wma'

let { channels, sampleRate, bitRate, packets } = demuxASF(buffer)

API

decode(src): Promise<AudioData>

Whole-file decode. Accepts Uint8Array or ArrayBuffer.

decoder(): Promise<WMADecoder>

Creates a decoder instance.

  • dec.decode(data): decode a Uint8Array or ArrayBuffer chunk.
  • dec.flush(): decode a buffered variable-size packet or return an empty result.
  • dec.free(): release WASM memory.
demuxASF(buf): ASFInfo

Parse ASF container without decoding. Returns stream properties and raw packets.

Formats

  • WMA v1 (0x0160)
  • WMA v2 (0x0161)
  • WMA Pro (0x0162)
  • WMA Lossless (0x0163)

Building WASM

npm run build

build.sh configures FFmpeg from the shared lib/ffmpeg submodule (release/7.1, as @audio/decode-eac3 and @audio/decode-ape) with only the four WMA decoders, and links the glue in src/wma_glue.c.

License

ॐ · LGPL-2.1-or-later, inherited from the bundled FFmpeg WMA decoders (FFmpeg release/7.1 at commit 3978a28, built without --enable-gpl; see build.sh and LICENSE.ffmpeg). Corresponding source: that FFmpeg commit, with build.sh and src/wma_glue.c.

Keywords