{"id":16134,"library":"node-audiorecorder","title":"Node.js Audio Recorder","description":"node-audiorecorder is a Node.js module designed for recording audio, delivering a 16-bit signed-integer linear pulse modulation WAV stream. It acts as a wrapper around external system utilities like SoX ('rec' or 'sox' commands) or ALSA's 'arecord' utility, which must be installed and available in the system's PATH. This package is currently at version 3.0.0 and offers robust control over recording parameters such as sample rate, bit depth, channels, encoding, and silence detection. Its primary differentiator is providing a programmatic interface to common command-line audio recording tools, making it suitable for applications requiring real-time audio input processing or storage. While its release cadence appears sporadic based on recent releases, the latest major version indicates ongoing maintenance and improvements.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/RedKenrok/node-audiorecorder","tags":["javascript","audio","recording","sox","rec","arecord","wav","wave"],"install":[{"cmd":"npm install node-audiorecorder","lang":"bash","label":"npm"},{"cmd":"yarn add node-audiorecorder","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-audiorecorder","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for audio recording on most systems; provides 'rec' or 'sox' commands.","package":"SoX","optional":false},{"reason":"Alternative to SoX for audio recording, primarily on Linux systems.","package":"ALSA (arecord)","optional":true},{"reason":"Linux-specific dependency for SoX to ensure support for various audio formats.","package":"libsox-fmt-all","optional":true}],"imports":[{"note":"The README and examples primarily show CommonJS `require`. While ESM might be supported, CommonJS is the demonstrated approach for direct instantiation.","wrong":"import AudioRecorder from 'node-audiorecorder'","symbol":"AudioRecorder","correct":"const AudioRecorder = require('node-audiorecorder')"},{"note":"Configuration options are passed directly to the constructor as an object, not imported as named exports from the module.","wrong":"import { options } from 'node-audiorecorder'","symbol":"options object","correct":"const options = { /* ... */ }"}],"quickstart":{"code":"const AudioRecorder = require('node-audiorecorder');\nconst fs = require('fs');\nconst path = require('path');\n\n// IMPORTANT: Ensure SoX or Arecord is installed on your system\n// For Linux: sudo apt-get install sox libsox-fmt-all\n// For MacOS: brew install sox\n// For Windows: Download binaries from sox.sourceforge.net\n\nconst outputFilePath = path.join(__dirname, 'output.wav');\n\nconst options = {\n  program: `rec`, // Try `arecord` if on Linux and `rec` doesn't work\n  device: null,   // Set e.g. `hw:1,0` if you have multiple devices\n  bits: 16,\n  channels: 1,\n  encoding: `signed-integer`,\n  format: `S16_LE`,\n  rate: 16000,\n  type: `wav`,\n  silence: 5, // Stop recording after 5 seconds of silence\n  thresholdStart: 0.5,\n  thresholdStop: 0.5,\n  keepSilence: true\n};\n\nconst logger = console; // Optional: for debugging\n\nconst audioRecorder = new AudioRecorder(options, logger);\n\n// Create a write stream to save the audio to a file\nconst fileStream = fs.createWriteStream(outputFilePath, { encoding: 'binary' });\n\n// Pipe the audio stream to the file\naudioRecorder.stream().pipe(fileStream);\n\nconsole.log('Starting audio recording... (will stop after 10 seconds or 5s silence)');\n\naudioRecorder.start();\n\n// Stop recording after 10 seconds for demonstration\nsetTimeout(() => {\n  audioRecorder.stop();\n  console.log(`Recording stopped. Audio saved to ${outputFilePath}`);\n  fileStream.end();\n}, 10000);\n\n// Handle errors from the recording process\naudioRecorder.on('error', (err) => {\n  console.error('Recording error:', err);\n});","lang":"javascript","description":"This quickstart demonstrates how to initialize the AudioRecorder, start a recording session, and pipe the output stream to a WAV file. It includes necessary external dependency setup comments and error handling."},"warnings":[{"fix":"Install SoX (sudo apt-get install sox libsox-fmt-all on Linux, brew install sox on macOS, download binaries for Windows) or ensure 'arecord' is available on Linux systems.","message":"This module is a wrapper around system utilities (SoX/arecord). These external tools are not bundled and must be manually installed and present in the system's PATH for node-audiorecorder to function.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For Windows users, downgrade SoX to version 14.4.1 to avoid continuous recording issues. This is a known compatibility problem with specific SoX versions.","message":"On Windows 10, using SoX version 14.4.2 or later can lead to issues with continuous recording that does not stop correctly.","severity":"gotcha","affected_versions":">=14.4.2 (SoX)"},{"fix":"For `arecord`, run `arecord -l` to list available devices and specify the correct device string (e.g., `hw:1,0`) in the `options.device` parameter. Consult SoX/arecord documentation for device enumeration.","message":"Incorrect or unavailable audio device selection can prevent recording or result in silence. The `device` option might need to be explicitly set.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure SoX is installed on your operating system and its executable directory is included in your system's PATH environment variable.","cause":"The 'sox' command (or 'rec' which is part of SoX) is not found in the system's PATH.","error":"Error: spawn sox ENOENT"},{"fix":"Ensure ALSA utilities are installed (e.g., `sudo apt-get install alsa-utils` on Debian/Ubuntu) and 'arecord' is available in your PATH. Consider using `program: 'rec'` if SoX is installed.","cause":"The 'arecord' command is not found in the system's PATH, or ALSA utilities are not installed.","error":"Error: spawn arecord ENOENT"},{"fix":"Switch `options.program` to `rec` or `sox` if you require silence detection features. If using `arecord`, you will need to implement silence detection logic separately.","cause":"The `silence`, `thresholdStart`, `thresholdStop`, and `keepSilence` options are only available when using `rec` or `sox` programs, not `arecord`.","error":"Warning: 'silence' ignored for program 'arecord'."}],"ecosystem":"npm"}