You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
default: $(LIBOPUS_ENCODER)$(LIBOPUS_ENCODER_MIN)$(LIBOPUS_DECODER)$(LIBOPUS_DECODER_MIN)$(RECORDER)$(RECORDER_MIN)$(WAVE_WORKER)$(WAVE_WORKER_MIN) test
Copy file name to clipboardExpand all lines: README.md
+59-33
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,33 @@
1
1
# Opus & Wave Recorder
2
2
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.
4
-
Encoded and muxed audio will be returned as typedArray in `dataAvailable` event.
3
+
A javascript library to encode the output of Web Audio API nodes in Ogg Opus or WAV format using WebAssembly.
5
4
6
-
For legacy asm.js, please use version 1.2.0
7
5
8
-
### Usage
6
+
#### Libraries Used
7
+
8
+
- Libopus: v1.2.1 compiled with emscripten 1.37.28
9
+
- speexDSP: 1.2RC3 compiled with emscripten 1.37.28
9
10
11
+
#### Required Files
12
+
13
+
The required files are in the `dist` folder. Unminified sources are in `dist-unminified`.
14
+
Examples for recording, encoding, and decoding are in `examples` folder.
10
15
11
16
---------
17
+
### Usage
18
+
19
+
12
20
#### Constructor
13
21
14
22
The `Recorder` object is available in the global namespace and supports CommonJS and AMD imports.
15
23
16
24
```js
17
25
var rec =newRecorder([config]);
18
26
```
27
+
19
28
Creates a recorder instance.
20
29
21
-
-**config** - An optional configuration object (see **config** section below)
30
+
-**config** - An optional configuration object.
22
31
23
32
24
33
---------
@@ -41,7 +50,6 @@ Creates a recorder instance.
41
50
-**streamPages** - (*optional*) `dataAvailable` event will fire after each encoded page. Defaults to `false`.
42
51
43
52
44
-
---------
45
53
#### Config Options for WAV recorder
46
54
47
55
-**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`.
**addEventListener** will add an event listener to the event target. Available events are `streamError`, `streamReady`, `dataAvailable`, `start`, `pause`, `resume` and `stop`.
64
-
65
-
```js
66
-
rec.initStream()
67
-
```
68
-
69
-
**initStream** will request the user for permission to access the the audio stream and raise `streamReady` or `streamError`.
70
-
Returns a Promise which resolves the audio stream when it is ready.
71
-
72
67
```js
73
68
rec.pause()
74
69
```
75
70
76
71
**pause** will keep the stream and monitoring alive, but will not be recording the buffers. Will raise the pause event. Subsequent calls to **resume** will add to the current recording.
**removeEventListener** will remove an event listener from the event target.
83
-
84
73
```js
85
74
rec.resume()
86
75
```
@@ -94,10 +83,10 @@ rec.setMonitorGain( gain )
94
83
**setMonitorGain** will set the volume on what will be passed to the monitor. Monitor level does not affect the recording volume. Gain is an a-weighted value between `0` and `1`.
95
84
96
85
```js
97
-
rec.start()
86
+
rec.start( [sourceNode] )
98
87
```
99
88
100
-
**start**will initalize the workerand begin capturing audio if the audio stream is ready. Will raise the `start`event when started.
89
+
**start**Initalizes the worker, audio context, and an audio stream and begin capturing audio. Returns a promise which resolves when recording is started. Will callback `onstart` when started. Optionally accepts a source node which can be used in place of initializing the microphone stream. For iOS support, `start`needs to be initiated from a user action.
101
90
102
91
```js
103
92
rec.stop()
@@ -109,7 +98,7 @@ rec.stop()
109
98
rec.clearStream()
110
99
```
111
100
112
-
**clearStream** will stop and delete the stream got from `initStream`, you will only ever call this manually if you have `config.leaveStreamOpen` set to `true`.
101
+
**clearStream** will stop and delete the stream as well as close the audio context. You will only ever call this manually if you have `config.leaveStreamOpen` set to `true`.
Returns a truthy value indicating if the browser supports recording.
123
112
124
113
114
+
---------
115
+
#### Callback Handlers
116
+
117
+
```js
118
+
rec.ondataavailable( arrayBuffer )
119
+
```
120
+
A callback which returns an array buffer of audio data. If `streamPages` is `true`, this will be called with each page of encoded audio. If `streamPages` is `false`, this will be called when the recording is finished with the complete data.
121
+
122
+
123
+
```js
124
+
rec.onpause()
125
+
```
126
+
127
+
A callback which occurs when media recording is paused.
128
+
129
+
```js
130
+
rec.onresume()
131
+
```
132
+
133
+
A callback which occurs when media recording resumes after being paused.
134
+
135
+
136
+
```js
137
+
rec.onstart()
138
+
```
139
+
140
+
A callback which occurs when media recording starts.
141
+
142
+
```js
143
+
rec.onstop()
144
+
```
145
+
146
+
A callback which occurs when media recording ends.
147
+
148
+
```js
149
+
rec.onstreamerror( error )
150
+
```
151
+
152
+
A callback which occurs when a stream error occurs.
153
+
154
+
125
155
---------
126
156
### Browser Support
127
157
@@ -146,6 +176,7 @@ Unsupported:
146
176
- macOS Safari v11 native opus playback not yet supported
147
177
- iOS Safari v11 native opus playback not yet supported
148
178
- Microsoft Edge native opus playback not yet supported
179
+
- iOS Safari requires `rec.start()` to be called from a user initiated event
149
180
150
181
151
182
---------
@@ -187,8 +218,3 @@ Clean the dist folder and git submodules:
187
218
make clean
188
219
```
189
220
190
-
191
-
---------
192
-
### Required Files
193
-
194
-
The required files to record audio to ogg/opus are `dist/recorder.min.js` and `dist/encoderWorker.min.js`. Optionally `dist/decoderWorker.min.js` will help decode ogg/opus files and `dist/waveWorker.min.js` is a helper to transform floating point PCM data into wave/pcm. The source files `src/encoderWorker.js` and `src/decoderWorker.js` do not work without building process; it will produce an error `ReferenceError: _malloc is not defined`. You need to either use compiled file in `dist/` folder or build by yourself.
0 commit comments