Package detail

node-audiorecorder

RedKenrok1.4kMIT3.0.0

Record audio via node using SoX or Arecord.

audio, recording, sox, rec

readme

npm package @latest License agreement Open issues on GitHub

Audio recorder

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.

Installation

npm install node-audiorecorder

Dependencies

This module requires you to install SoX and it must be available in your \$PATH.

For Linux

sudo apt-get install sox libsox-fmt-all

For MacOS

brew install sox

For Windows

Download the binaries

Usage

Constructor

// 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 = {
  program: `rec`, // Which program to use, either `arecord`, `rec`, or `sox`.
  device: null, // Recording device to use, e.g. `hw:1,0`

  bits: 16, // Sample size. (only for `rec` and `sox`)
  channels: 1, // Channel count.
  encoding: `signed-integer`, // Encoding type. (only for `rec` and `sox`)
  format: `S16_LE`, // Encoding type. (only for `arecord`)
  rate: 16000, // Sample rate.
  type: `wav`, // Format type.

  // Following options only available when using `rec` or `sox`.
  silence: 2, // Duration of silence in seconds before it stops recording.
  thresholdStart: 0.5, // Silence threshold to start recording.
  thresholdStop: 0.5, // Silence threshold to stop recording.
  keepSilence: true, // Keep the silence in the recording.
}
// 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)

If you can't capture any sound with 'arecord' try to running 'arecord -l' to which devices are available.

See the arecord documentation for more detail on its options.

See the sox documentation for more detail on the rec and sox options.

Methods

// 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()

Examples

See the examples directory for example usage.

For another example see the node-hotworddetector module, or Electron-VoiceInterfaceBoilerplate's input.js.

Troubleshooting

Windows continues recording

If you have issues with continues recording on Windows 10 with SoX 14.4.2 or later, install version 14.4.1 instead.

License

MIT license

changelog

Changelog

3.0.0 (2022-02-14)

Changed

  • Allow for multiple instance at once.
  • Updated development dependencies.

2.0.1 (2020-04-28)

Changed

  • Updated development dependencies.

2.0.0 (2020-01-16)

Removed

  • Device option removed for sox and rec commands.

1.4.1 (2019-03-13)

Changed

  • Updated dependencies.

1.4.0 (2018-12-27)

Added

  • keepSilence option added fo sox and rec only. The option enables or disabled the -l flag which controls whether the silence is part of the recording or not.

1.3.0-beta.0 (2018-12-12)

Added

  • Opened up the format argument of the audio recorder options. (only for arecord)

Changed

  • Fixed arecord command generation.

1.2.0 (2018-11-09)

Changed

  • Added -l to silence effect, therefore the silence not removed from the start of the recording.
  • Default values of thresholdStart and thresholdStop are both set to 1.
  • Fixed duration of silence effect since duration parameters need to have a decimal. For example 2.0 instead of 2.

Removed

  • sampleRate and threshold options removed.

1.1.6 (2018-11-08)

Added

  • Example added to examples directory, and changed example.js to examples/print-command.js.

Fixed

  • Fixed silence effect.

1.1.5 (2018-10-24)

Added

  • Added bits, encoding, rate, and type properties to options, which allows greater control over output.

Changed

  • sampleRate option renamed to rate, legacy support still available.

1.1.4 (2018-10-23)

Added

  • Tests added with continues integration and code coverage.

Changed

  • Clarified examples in README.md.

Fixed

  • example.js fixed.
  • Default values fixed in README.md.

1.1.3 (2018-09-18)

Added

  • CHANGELOG.md added.
  • eslint module added as dev dependency
  • .eslintrc.json file added.

Changed

  • Restructured project files.