LinguaRecorder is a fast cross-browser voice recording JS library.
- Easily record your users directly from their browser (no software/plugin/whatsoever needed)
- Both desktop and mobile friendly
- Fully configurable
- Intelligent cutting to avoid blanks at the start/end of a record
- Saturation control to cancel/discard bad records
- Whole bunch of events allowing you to asynchronousely manage your user's actions
- Wide possibilities for exporting your records, including:
- Play in browser
- Direct download
- WAV-encoded Blob (to send to an API for exemple)
- URL object
- ...
Tested in the following browsers/versions:
- Firefox 25+
- Chrome 22+
- Firefox for android* 57+
- Chrome for android* 63+
- Microsoft Edge 12+
- Safari 11+
- Opera 18+
It may work on older versions of the browsers marked with *, but it has not been tested.
The LinguaRecorder sandbox allows you to get familiar with (hardly) all features of the library, and to play with it's configuration possibilities.
The demo folder contain several other implementation examples.
Get the code:
- Clone github repository:
git clone https://github.com/lingua-libre/LinguaRecorder.git
- Install with npm:
npm install lingua-recorder
- Use a CDN: todo
Then include the two files stored in the src folder in your HTML page:
<script src="/path/to/AudioRecord.js"></script>
<script src="/path/to/LinguaRecorder.js"></script>
<script>
var recorder = new LinguaRecorder();
...
</script>
to do
Set to true to wait for voice detection before effectively starting the record when calling the start() method.
Set to true to stop the record when there is a silence.
Set the size of the samples buffers. Could be 0 (let the browser choose the best one) or one of the following values: 256, 512, 1024, 2048, 4096, 8192, 16384; the less the more precise, the higher the more efficient.
Maximum time (in seconds) after which it is necessary to stop recording. Set to 0 (default) for no time limit.
Tell what to do when a record is saturated. Accepted values are 'none' (default), 'cancel' and 'discard'.
Amplitude value between 0 and 1 included. Only used if onSaturate is different from 'none'. Threshold above which a record should be flagged as saturated.
Amplitude value between 0 and 1 included. Only used if autoStart is set to true. Amplitude to reach to auto-start the recording.
Amplitude value between 0 and 1 included. Only used if autoStop is set to true. Amplitude not to exceed in a stopDuration interval to auto-stop recording.
Duration value in seconds. Only used if autoStop is set to true. Duration during which not to exceed the stopThreshold in order to auto-stop recording.
Duration value in seconds. Only used if autoStart is set to true.
Duration value in seconds. Only used if autoStop is set to true.
Duration value in seconds. Discard the record if it last less than minDuration. Default value to 0.15, use 0 to disable.
Start to record.
If autoStart is set to true, enter in listening state and postpone the start of the recording when a voice will be detected.
- ⇒
boolean
Has the record being started or not. If false, that means either the recorder is not initialized yet, or a record is already in progress.
Switch the record to the pause state.
While in pause, all the inputs comming from the microphone will be ignored. To resume to the recording state, just call the start() method again. It is also still possible to stop() or cancel() a record, and you have to do so upstream if you wish to start a new one.
- ⇒
boolean
Has the record being paused or not.
Stop the recording process and fire the record to the user.
Depending of the configuration, this method could discard the record if it fails some quality controls (duration and saturation).
To start a new record afterwards, just call the start() method again.
- cancelRecord:
boolean
optional
If set to true, cancel and discard the record in any cases. - ⇒
boolean
Has the record being stopped or not.
Stop a recording, but without saving the record. This is an alias for stop( true )
.
- ⇒
boolean
Has the record being stopped or not.
Toggle between the recording and stopped state.
Attach a handler function to a given event.
- event:
string
Name of an event. See the dedicated section for a list of all the events available. - handler:
function
A function to execute when the event is triggered. - ⇒
this
Remove all the handler function from an event.
- event:
string
Name of an event. See the dedicated section for a list of all the events available. - ⇒
this
Add an extra AudioNode
This can be used to draw a live visualisation of the sound, or to perform some live editing tasks on the stream before it is recorded. See https://developer.mozilla.org/fr/docs/Web/API/AudioNode
Note that it can produce a little interrupt in the record if you are in listening or recording state.
- node:
AudioNode
Node to connect inside the recording context. - ⇒
this
Remove an extra AudioNode previously added with connectAudioNode.
Note that it can produce a little interrupt in the record if you are in listening or recording state.
- node:
AudioNode
Node to disconnect from the recording context. - ⇒
this
Return the current duration of the record.
- ⇒
number
The duration in seconds
Return the current state of the recorder.
- ⇒
string
One of the following: 'stop', 'listening', 'recording', 'paused'
Return the audioContext initialised and used by the recorder.
see https://developer.mozilla.org/fr/docs/Web/API/AudioContext
- ⇒
AudioContext
The AudioContext object used by the recorder.
- ready:
MediaStream
The user has allowed your script to use the microphone, the recorder is ready to start a record. - readyFail:
DOMException
Something got wrong during the initialisation; maybe the user has no microphone, or he has not allowed you to use it. For the full exceptions list, see https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Exceptions. - started: A record has just started; or to say it differently the recorder switched to the record state.
- recording:
Float32Array
Firered when in the record state, each time it has N new samples available (N =bufferSize
); the given parameter is an array containing those new samples. - listening:
Float32Array
Same as the recording event, but when the recorder is in the listen state. - saturated: Fired each time the record get saturated.
- paused: The record has just being paused; or to say it differently the recorder switched to the pause state.
- stoped:
AudioRecord
The record has just being stopped; or to say it differently the recorder switched to the stop state. It includes a reference to an AudioRecord, containing the stopped record. - canceled:
string
The record has just being canceled, thestring
contains the reason of the cancelation, one of the following: 'asked', 'saturated' (whenonSaturate
is set to 'cancel'), 'tooShort' (whenminDuration
is not reached).
- stop:
default
Not recording yet, what are you waiting? - listen: You've hit start, but you've not sepaken yet, it's time to do so! (only when
autoStart
is true) - record: Currently recording. That's amazing, isn't it?
- pause: It was recording, but a dog just walked in so you paused the record the time to kick it away, but you wish to finish it later.
to do
The LinguaRecorder was originaly a part of LinguaLibre, developped by Nicolas Vion (@zmoostik), but has then been splitted out and completely rewritten by Antoine Lamielle (@0x010C).
Released under the GPL v3 License.