JSPM

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

Audio recorder for Node.js

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

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 = {
  channels: '1',			// Amount of channels to record.
  device: null,			// Recording device to use.
  program: 'rec',			// Which program to use, either 'arecord', 'rec', or 'sox'.
  sampleRate: 16000,		// Audio sample rate in hz.
  silence: '2',			// Time of silence in seconds before it stops recording.
  threshold: 0.5,			// Silence threshold (only for 'rec' and 'sox').
  thresholdStart: null,	// Silence threshold to start recording, overrides threshold (only for 'rec' and 'sox').
  thresholdEnd: null,		// Silence threshold to end recording, overrides threshold (only for 'rec' and 'sox').
};
// Optional parameter intended for debugging.
// The object has to implement a log and warn function.
const logger = {
  log: console.log,
  warn: console.warn
};

// 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();
// Stops the recording process and pauses the stream.
audioRecorder.Pause();
// Starts the recording process and resumes the stream.
audioRecorder.Resume();
// Returns the stream of the recording process.
audioRecorder.Stream();

Example

// Imports modules.
const fs = require('fs');
const AudioRecorder = require('node-audiorecorder');

// Initialize recorder and file stream.
let audioRecorder = new AudioRecorder(null, console);
let file = fs.createWriteStream('recording.wav', { encoding: 'binary' });

// Start and write to the file.
audioRecorder.start().stream().pipe(file);

For another example see the node-hotworddetector module.