Skip to content

Commit 8b70395

Browse files
authored
Merge pull request #180 from chris-rudmin/stream-incoming
Stream incoming
2 parents b1f6fec + f8de026 commit 8b70395

18 files changed

+387
-115
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules/
2-
2+
3+
.DS_Store
4+
/.idea/
5+
/*.iml

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LIBOPUS_DECODER_MIN=$(OUTPUT_DIR)/decoderWorker.min.js
1212
LIBOPUS_DECODER=$(OUTPUT_DIR_UNMINIFIED)/decoderWorker.js
1313
LIBOPUS_DIR=./opus
1414
LIBOPUS_OBJ=$(LIBOPUS_DIR)/.libs/libopus.a
15-
LIBOPUS_ENCODER_EXPORTS:='_opus_encoder_create','_opus_encode_float','_opus_encoder_ctl'
15+
LIBOPUS_ENCODER_EXPORTS:='_opus_encoder_create','_opus_encode_float','_opus_encoder_ctl','_opus_encoder_destroy'
1616
LIBOPUS_DECODER_EXPORTS:='_opus_decoder_create','_opus_decode_float','_opus_decoder_destroy'
1717

1818
LIBSPEEXDSP_DIR=./speexdsp

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Creates a recorder instance.
5252
- **originalSampleRateOverride** - (*optional*) Override the ogg opus 'input sample rate' field. Google Speech API requires this field to be `16000`.
5353
- **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`.
5454
- **streamPages** - (*optional*) `dataAvailable` event will fire after each encoded page. Defaults to `false`.
55+
- **reuseWorker** - (*optional*) If true, the worker is not automatically destroyed when `stop` is called. Instead, it is reused for subsequent `start` calls and must be explicitly destroyed after stopping by calling `destroyWorker`. Defaults to `false`.
5556

5657

5758
#### Config options for WAV recorder
@@ -64,10 +65,10 @@ Creates a recorder instance.
6465

6566

6667
```js
67-
rec.pause()
68+
rec.pause([flush])
6869
```
6970

70-
**pause** will keep the stream and monitoring alive, but will not be recording the buffers. Will call the `onpause` callback when paused. Subsequent calls to **resume** will add to the current recording.
71+
**pause** will keep the stream and monitoring alive, but will not be recording the buffers. If `flush` is `true` and `streamPages` is set, any pending encoded frames of data will be flushed, and it will return a promise that only resolves after the frames have been flushed to `ondataavailable`. Will call the `onpause` callback when paused. Subsequent calls to **resume** will add to the current recording.
7172

7273
```js
7374
rec.resume()
@@ -99,6 +100,26 @@ rec.stop()
99100

100101
**stop** will cease capturing audio and disable the monitoring and mic input stream. Will request the recorded data and then terminate the worker once the final data has been published. Will call the `onstop` callback when stopped.
101102

103+
```js
104+
rec.destroyWorker()
105+
```
106+
107+
**destroyWorker** will destroy the worker freeing up the browser resources. If the recorder is re-started, a new worker will be created. Note that `destroyWorker` is automatically called when stopping unless `reuseWorker` is true.
108+
109+
```js
110+
rec.loadWorker()
111+
```
112+
113+
**loadWorker** triggers pre-loading of the worker. This can reduce the startup latency when calling `start`. Call `destroyWorker` to clean the worker when the recorder is stopped/not started, or it will be automatically cleaned up after stopping unless `reuseWorker` is true.
114+
115+
---------
116+
#### Instance Fields
117+
118+
```js
119+
rec.encodedSamplePosition
120+
```
121+
122+
Reads the currently encoded sample position (the number of samples up to and including the most recent data provided to `ondataavailable`). For Opus, the encoded sample rate is always 48kHz, so a time position can be determined by dividing by 48000.
102123

103124
---------
104125
#### Static Methods

dist-unminified/encoderWorker.js

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

dist-unminified/encoderWorker.wasm

58 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)