JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2613
  • Score
    100M100P100Q118499F
  • License MIT

Record audio via node using a SOX.

Package Exports

  • node-audiorecorder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-audiorecorder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm package @latest Travis-ci status

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 --save 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 = {
  // Amount of channels to record.
  channels: 1,
  // Recording device to use.
  device: null,
  // Which program to use, either 'arecord', 'sox', and 'rec'.
  program: 'rec',
  // 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'.

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

The following is a shortend version of the example script found in this repository. Do note ../library references this module.

// Imports modules.
const fs = require(`fs`),
    path = require(`path`);
const AudioRecorder = require(`../library`);
// Constants.
const DIRECTORY = `RECORDINGS`;

// Initialize recorder and file stream.
const audioRecorder = new AudioRecorder({
    program: process.platform === `win32` ? `sox` : `rec`,
    silence: 0
});

// Log the generated command.
console.log(`${audioRecorder.options.program} ${audioRecorder.command.arguments.join(` `)}`);

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

ISC license