Skip to content

Commit 074e610

Browse files
authored
Merge pull request #106 from chris-rudmin/webassembly
Support Webassembly
2 parents 9de393e + e97f63b commit 074e610

16 files changed

+262
-193
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
INPUT_DIR=./src
22
OUTPUT_DIR=./dist
3-
EMCC_OPTS=-O3 --llvm-lto 1 --memory-init-file 0 -s NO_DYNAMIC_EXECUTION=1 -s NO_FILESYSTEM=1
4-
DEFAULT_EXPORTS:='_free','_malloc'
3+
EMCC_OPTS=-O3 --llvm-lto 1 --memory-init-file 0 -s NO_DYNAMIC_EXECUTION=1 -s NO_FILESYSTEM=1 -s WASM=1
54

65
LIBOPUS_ENCODER_SRC=$(INPUT_DIR)/encoderWorker.js
76
LIBOPUS_DECODER_SRC=$(INPUT_DIR)/decoderWorker.js
@@ -30,7 +29,8 @@ clean:
3029
mkdir $(OUTPUT_DIR)
3130

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

3535
.PHONY: test
3636

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

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

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

5858
$(RECORDER): $(RECORDER_SRC)
5959
npm run webpack -- --output-library Recorder --output-library-target umd --optimize-minimize $(RECORDER_SRC) $@

README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Opus & Wave Recorder
22

3-
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.
3+
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.
44
Encoded and muxed audio will be returned as typedArray in `dataAvailable` event.
55

6+
For legacy asm.js, please use version 1.2.0
7+
68
### Usage
79

810

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

2123

2224
---------
23-
#### Config
25+
#### Config options for OGG OPUS encoder
2426

2527
- **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`.
2628
- **encoderApplication** - (*optional*) Supported values are: `2048` - Voice, `2049` - Full Band Audio, `2051` - Restricted Low Delay. Defaults to `2049`.
@@ -37,7 +39,18 @@ Creates a recorder instance.
3739
- **originalSampleRateOverride** - (*optional*) Override the ogg opus 'input sample rate' field. Google Speech API requires this field to be `16000`.
3840
- **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`.
3941
- **streamPages** - (*optional*) `dataAvailable` event will fire after each encoded page. Defaults to `false`.
40-
- **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`
42+
43+
44+
---------
45+
#### Config Options for WAV recorder
46+
47+
- **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`.
48+
- **encoderPath** - (*optional*) Path to `encoderWorker.min.js` or `waveWorker.min.js` worker script. Defaults to `encoderWorker.min.js`
49+
- **leaveStreamOpen** - (*optional*) Keep the stream around when trying to `stop` recording, so you can re-`start` without re-`initStream`. Defaults to `false`.
50+
- **mediaTrackConstraints** - (*optional*) Object to specify [media track constraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints). Defaults to `true`.
51+
- **monitorGain** - (*optional*) Sets the gain of the monitoring output. Gain is an a-weighted value between `0` and `1`. Defaults to `0`
52+
- **numberOfChannels** - (*optional*) The number of channels to record. `1` = mono, `2` = stereo. Defaults to `1`. Maximum `2` channels are supported.
53+
- **wavBitDepth** - (*optional*) Desired bit depth of the WAV file. Defaults to `16`. Supported values are `8`, `16`, `24` and `32` bits per sample.
4154

4255

4356
---------
@@ -115,10 +128,10 @@ Returns a truthy value indicating if the browser supports recording.
115128
Supported:
116129
- Chrome v58
117130
- Firefox v53
118-
- Microsoft Edge
131+
- Microsoft Edge v41
119132
- Opera v44
120-
- Safari v11
121-
- iOS 11 Safari
133+
- macOS Safari v11
134+
- iOS Safari v11
122135

123136
Unsupported:
124137
- IE 11 and below
@@ -129,9 +142,9 @@ Unsupported:
129142
### Known Issues
130143

131144
- Firefox does not support sample rates above 48000Hz: https://bugzilla.mozilla.org/show_bug.cgi?id=1124981
132-
- Safari v11 does not sample rates above 44100Hz
133-
- Safari v11 native opus playback not yet supported
134-
- iOS 11 Safari native opus playback not yet supported
145+
- macOS Safari v11 does not sample rates above 44100Hz
146+
- macOS Safari v11 native opus playback not yet supported
147+
- iOS Safari v11 native opus playback not yet supported
135148
- Microsoft Edge native opus playback not yet supported
136149

137150

bower.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"main": [
55
"dist/recorder.min.js",
66
"dist/encoderWorker.min.js",
7+
"dist/encoderWorker.min.wasm",
78
"dist/decoderWorker.min.js",
9+
"dist/decoderWorker.min.wasm",
810
"dist/waveWorker.min.js"
911
],
1012
"license": [
@@ -26,7 +28,8 @@
2628
"Streamer",
2729
"Audio",
2830
"Microphone",
29-
"Recorder"
31+
"Recorder",
32+
"WebAssembly"
3033
],
3134
"repository": {
3235
"type": "git",

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
machine:
22
node:
3-
version: 6.1.0
3+
version: 8.9.1

dist/decoderWorker.min.js

+1-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/decoderWorker.min.wasm

125 KB
Binary file not shown.

dist/encoderWorker.min.js

+1-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/encoderWorker.min.wasm

216 KB
Binary file not shown.

dist/waveWorker.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opus-recorder",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "A library for recording opus encoded audio",
55
"homepage": "https://github.com/chris-rudmin/Recorderjs",
66
"author": "Chris Rudmin",
@@ -15,14 +15,17 @@
1515
"Microphone",
1616
"Recorder",
1717
"Wav",
18-
"Wave"
18+
"Wave",
19+
"WebAssembly"
1920
],
2021
"license": "MIT",
2122
"main": "dist/recorder.min.js",
2223
"files": [
2324
"dist/recorder.min.js",
2425
"dist/encoderWorker.min.js",
26+
"dist/encoderWorker.min.wasm",
2527
"dist/decoderWorker.min.js",
28+
"dist/decoderWorker.min.wasm",
2629
"dist/waveWorker.min.js"
2730
],
2831
"repository": {

0 commit comments

Comments
 (0)