Audio recorder for Node.js, delivers a 16-bit signed-integer linear pulse modulation WAV stream. Based of Gilles De Mey's node-record-lpcm16.
npm install --save node-audiorecorder
This module requires you to install SoX and it must be available in your $PATH.
sudo apt-get install sox libsox-fmt-all
brew install sox
// Import module.
const AudioRecorder = require('node-audiorecorder');
// Options is an optional parameter for the constructor call.
// If an option is not given the default value, as seen below, will be used.
const options = {
// Amount of channels to record.
channels: 1,
// Recording device to use.
device: null,
// Which program to use, either 'arecord', 'sox', and 'rec'.
program: 'sox',
// Audio sample rate in hz.
sampleRate: 16000,
// Time of silence in seconds before it stops recording.
silence: 2,
// Silence threshold (only for 'sox' and 'rec').
threshold: 0.5,
// Silence threshold to start recording, overrides threshold (only for 'sox' and 'rec').
thresholdStart: null,
// Silence threshold to stop recording, overrides threshold (only for 'sox' and 'rec').
thresholdStop: null,
};
// Optional parameter intended for debugging.
// The object has to implement a log and warn function.
const logger = console;
// Create an instance.
let audioRecorder = new AudioRecorder(options, logger);
'arecord' might not work on all operating systems. If you can't capture any sound with 'arecord', try to change device to 'arecord -l'.
// Creates and starts the recording process.
audioRecorder.Start();
// Stops and removes the recording process.
audioRecorder.Stop();
// Returns the stream of the recording process.
audioRecorder.Stream();
See or run the example.js script to see or test it for yourself. If you want to use that code directly in your project DO update the require(./index.js)
to require(node-audiorecorder)
.
For another example see the node-hotworddetector module, or Electron-VoiceInterfaceBoilerplate's input.js.
If you have issues with continues recording on Windows 10 with SoX 14.4.2 or later, install version 14.4.1rc3 instead.