Skip to content

Commit

Permalink
Merge pull request #106 from chris-rudmin/webassembly
Browse files Browse the repository at this point in the history
Support Webassembly
  • Loading branch information
chris-rudmin authored Dec 2, 2017
2 parents 9de393e + e97f63b commit 074e610
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 193 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
INPUT_DIR=./src
OUTPUT_DIR=./dist
EMCC_OPTS=-O3 --llvm-lto 1 --memory-init-file 0 -s NO_DYNAMIC_EXECUTION=1 -s NO_FILESYSTEM=1
DEFAULT_EXPORTS:='_free','_malloc'
EMCC_OPTS=-O3 --llvm-lto 1 --memory-init-file 0 -s NO_DYNAMIC_EXECUTION=1 -s NO_FILESYSTEM=1 -s WASM=1

LIBOPUS_ENCODER_SRC=$(INPUT_DIR)/encoderWorker.js
LIBOPUS_DECODER_SRC=$(INPUT_DIR)/decoderWorker.js
Expand Down Expand Up @@ -30,7 +29,8 @@ clean:
mkdir $(OUTPUT_DIR)

test:
mocha
# Tests need to run relative to `dist` folder for wasm file import
cd $(OUTPUT_DIR); node --expose-wasm ../test.js

.PHONY: test

Expand All @@ -49,11 +49,11 @@ $(LIBSPEEXDSP_OBJ): $(LIBSPEEXDSP_DIR)

$(LIBOPUS_ENCODER): $(LIBOPUS_ENCODER_SRC) $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)
npm run webpack -- --output-library EncoderWorker --output-library-target umd --optimize-minimize $(LIBOPUS_ENCODER_SRC) $@
emcc -o $@ $(EMCC_OPTS) -s EXPORTED_FUNCTIONS="[$(DEFAULT_EXPORTS),$(LIBOPUS_ENCODER_EXPORTS),$(LIBSPEEXDSP_EXPORTS)]" --post-js $@ $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)
emcc -o $@ $(EMCC_OPTS) -s EXPORTED_FUNCTIONS="[$(LIBOPUS_ENCODER_EXPORTS),$(LIBSPEEXDSP_EXPORTS)]" --pre-js $@ $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)

$(LIBOPUS_DECODER): $(LIBOPUS_DECODER_SRC) $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)
npm run webpack -- --output-library DecoderWorker --output-library-target umd --optimize-minimize $(LIBOPUS_DECODER_SRC) $@
emcc -o $@ $(EMCC_OPTS) -s EXPORTED_FUNCTIONS="[$(DEFAULT_EXPORTS),$(LIBOPUS_DECODER_EXPORTS),$(LIBSPEEXDSP_EXPORTS)]" --post-js $@ $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)
emcc -o $@ $(EMCC_OPTS) -s EXPORTED_FUNCTIONS="[$(LIBOPUS_DECODER_EXPORTS),$(LIBSPEEXDSP_EXPORTS)]" --pre-js $@ $(LIBOPUS_OBJ) $(LIBSPEEXDSP_OBJ)

$(RECORDER): $(RECORDER_SRC)
npm run webpack -- --output-library Recorder --output-library-target umd --optimize-minimize $(RECORDER_SRC) $@
Expand Down
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Opus & Wave Recorder

A javascript library to encode the output of Web Audio API nodes in Ogg Opus or WAV format. Audio encoded and decoded using libopus v1.2.1. Audio resampling is performed by speexDSP 1.2RC3.
A javascript library to encode the output of Web Audio API nodes in Ogg Opus or WAV format using WebAssembly. Audio encoded and decoded using libopus v1.2.1. Audio resampling is performed by speexDSP 1.2RC3.
Encoded and muxed audio will be returned as typedArray in `dataAvailable` event.

For legacy asm.js, please use version 1.2.0

### Usage


Expand All @@ -20,7 +22,7 @@ Creates a recorder instance.


---------
#### Config
#### Config options for OGG OPUS encoder

- **bufferLength** - (*optional*) The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to `4096`.
- **encoderApplication** - (*optional*) Supported values are: `2048` - Voice, `2049` - Full Band Audio, `2051` - Restricted Low Delay. Defaults to `2049`.
Expand All @@ -37,7 +39,18 @@ Creates a recorder instance.
- **originalSampleRateOverride** - (*optional*) Override the ogg opus 'input sample rate' field. Google Speech API requires this field to be `16000`.
- **resampleQuality** - (*optional*) Value between 0 and 10 which determines latency and processing for resampling. `0` is fastest with lowest quality. `10` is slowest with highest quality. Defaults to `3`.
- **streamPages** - (*optional*) `dataAvailable` event will fire after each encoded page. Defaults to `false`.
- **wavBitDepth** - (*optional*) Desired bit depth of the WAV file. Defaults to `16`. Supported values are `8`, `16`, `24` and `32` bits per sample. Only applies to `waveWorker.min.js`


---------
#### Config Options for WAV recorder

- **bufferLength** - (*optional*) The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to `4096`.
- **encoderPath** - (*optional*) Path to `encoderWorker.min.js` or `waveWorker.min.js` worker script. Defaults to `encoderWorker.min.js`
- **leaveStreamOpen** - (*optional*) Keep the stream around when trying to `stop` recording, so you can re-`start` without re-`initStream`. Defaults to `false`.
- **mediaTrackConstraints** - (*optional*) Object to specify [media track constraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints). Defaults to `true`.
- **monitorGain** - (*optional*) Sets the gain of the monitoring output. Gain is an a-weighted value between `0` and `1`. Defaults to `0`
- **numberOfChannels** - (*optional*) The number of channels to record. `1` = mono, `2` = stereo. Defaults to `1`. Maximum `2` channels are supported.
- **wavBitDepth** - (*optional*) Desired bit depth of the WAV file. Defaults to `16`. Supported values are `8`, `16`, `24` and `32` bits per sample.


---------
Expand Down Expand Up @@ -115,10 +128,10 @@ Returns a truthy value indicating if the browser supports recording.
Supported:
- Chrome v58
- Firefox v53
- Microsoft Edge
- Microsoft Edge v41
- Opera v44
- Safari v11
- iOS 11 Safari
- macOS Safari v11
- iOS Safari v11

Unsupported:
- IE 11 and below
Expand All @@ -129,9 +142,9 @@ Unsupported:
### Known Issues

- Firefox does not support sample rates above 48000Hz: https://bugzilla.mozilla.org/show_bug.cgi?id=1124981
- Safari v11 does not sample rates above 44100Hz
- Safari v11 native opus playback not yet supported
- iOS 11 Safari native opus playback not yet supported
- macOS Safari v11 does not sample rates above 44100Hz
- macOS Safari v11 native opus playback not yet supported
- iOS Safari v11 native opus playback not yet supported
- Microsoft Edge native opus playback not yet supported


Expand Down
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"main": [
"dist/recorder.min.js",
"dist/encoderWorker.min.js",
"dist/encoderWorker.min.wasm",
"dist/decoderWorker.min.js",
"dist/decoderWorker.min.wasm",
"dist/waveWorker.min.js"
],
"license": [
Expand All @@ -26,7 +28,8 @@
"Streamer",
"Audio",
"Microphone",
"Recorder"
"Recorder",
"WebAssembly"
],
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
machine:
node:
version: 6.1.0
version: 8.9.1
15 changes: 1 addition & 14 deletions dist/decoderWorker.min.js

Large diffs are not rendered by default.

Binary file added dist/decoderWorker.min.wasm
Binary file not shown.
16 changes: 1 addition & 15 deletions dist/encoderWorker.min.js

Large diffs are not rendered by default.

Binary file added dist/encoderWorker.min.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/waveWorker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opus-recorder",
"version": "1.2.0",
"version": "2.0.0",
"description": "A library for recording opus encoded audio",
"homepage": "https://github.com/chris-rudmin/Recorderjs",
"author": "Chris Rudmin",
Expand All @@ -15,14 +15,17 @@
"Microphone",
"Recorder",
"Wav",
"Wave"
"Wave",
"WebAssembly"
],
"license": "MIT",
"main": "dist/recorder.min.js",
"files": [
"dist/recorder.min.js",
"dist/encoderWorker.min.js",
"dist/encoderWorker.min.wasm",
"dist/decoderWorker.min.js",
"dist/decoderWorker.min.wasm",
"dist/waveWorker.min.js"
],
"repository": {
Expand Down
Loading

0 comments on commit 074e610

Please sign in to comment.