WASM Audio Decoders is a collection of Web Assembly audio decoder libraries that are highly optimized for browser use. Each module supports synchronous decoding on the main thread as well as asynchronous (threaded) decoding through a built in Web Worker implementation.
Web Assembly is a binary instruction format for a stack-based virtual machine that allows for near native code execution speed inside of a web browser. In practice, these decoders are just as fast, and in some cases faster, than the browser implementation.
Each decoder is built with inline WASM to reduce bundling complexity with transpilers like Webpack. The inlined WASM is encoded using yEnc for efficient binary encoding and is gzip compressed for reduced file size.
Pre-built minified JS files are available from NPM and in each decoder's dist
folder.
Decodes MPEG Layer I/II/III into PCM
- 74.5 KiB minified bundle size
- Browser and NodeJS support
- Built in Web Worker support
- Based on
mpg123
- Install using NPM
Decodes FLAC and Ogg FLAC data into PCM
- 65.2 KiB minified bundle size
- Browser and NodeJS support
- Built in Web Worker support
- Multichannel decoding (up to 8 channels)
- Supports full FLAC bit depth and sample rate.
- Based on
libFLAC
andcodec-parser
- Install using NPM
Decodes Ogg Opus data into PCM
- 108.0 KiB minified bundle size
- Browser and NodeJS support
- Built in Web Worker support
- Multichannel decoding (up to 255 channels)
- Based on
libopus
andcodec-parser
- Install using NPM
Decodes raw Opus audio frames into PCM
- 84.6 KiB minified bundle size
- Browser and NodeJS support
- Built in Web Worker support
- Multichannel decoding (up to 255 channels)
- Intended for users that already have Opus frames extracted from a container, i.e. (Ogg, Matroska (WEBM), or ISOBMFF (mp4))
- Based on
libopus
- Install using NPM
Decodes Ogg Vorbis data into PCM
- 97.6 KiB minified bundle size
- Browser and NodeJS support
- Built in Web Worker support
- Multichannel decoding (up to 255 channels)
- Supports full Vorbis sample rate.
- Based on
libvorbis
andcodec-parser
- Install using NPM
- Install Emscripten by following these instructions.
- This repository has been tested with Emscripten 3.1.46.
- Make sure to
source
the Emscripten path in the terminal you want build in.- i.e.
$ source path/to/emsdk/emsdk_env.sh
- i.e.
- Run
git submodule update --init
to clone down the git sub-modules. - Run
make configure
to configure the libraries. This may appear to hang forever at 100% CPU when "checking whether the C compiler works", but should eventually complete. - Run
npm i
to install the build tool dependencies. - Run
make clean
andmake
to build the libraries.- You can run
make -j8
where8
is the number of CPU cores on your system to speed up the build.
- You can run
- The builds will be located in each library's
dist
folder:
- Run
npm i
to install the build tool and test dependencies. - Run
npm run test
to run the test suite.
OggOpusDecoder
was originally based on AnthumChris/opus-stream-decoder.- This version has been optimized for size and for simple bundling in web applications:
- Everything is bundled in a single minified Javascript file for ease of use.
- Multichannel decoding (all 255 Opus channels) is supported.
- WASM binary is encoded inline using yEnc binary encoding and compressed using DEFLATE to significantly reduce bundle size.
- WASM compiler, minifier, and bundler options are tuned for best possible size and performance.
- This version has been optimized for size and for simple bundling in web applications:
puff
is included as a WASM build from madler/zlib and is used to decompress the WASM binary.
The source code that originates in this project is licensed under the MIT license. Please note that any external source code included by repository, such as the decoding libraries included as git submodules and compiled into the dist files, may have different licensing terms.