
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
node-microphone
Advanced tools
Microphone access in Node.js using arecord on Linux and SoX on Windows/macOS.
node-microphone provides microphone input in Node.js by spawning platform tools:
arecordrec from SoXsoxIt returns the underlying PCM stream and also exposes info, error, and optional data events through an EventEmitter API.
The current 0.2.0 release also improves a few rough edges from 0.1.6:
fileType: 'raw'Install the audio capture tool for your platform before using the package.
sudo apt-get install alsa-utilsrec command available in PATHsox available in PATHnpm install node-microphone
TypeScript declarations are bundled with the package. The package now targets Node.js 12+.
Compared with 0.1.6, version 0.2.0 adds and changes:
index.d.tsfileType option so Linux, macOS, and Windows can produce the same output type by defaultspawnOptions option for passing supported child_process.spawn() settingsclose event emitted when the recording process exitsendian, non-boolean useDataEmitter, or unsupported spawnOptions.stdioMicrophone instance can be started again after the child exitsconst Microphone = require('node-microphone');
const mic = new Microphone({
rate: '16000',
channels: '1',
fileType: 'raw',
});
const micStream = mic.startRecording();
if (micStream) {
micStream.pipe(myWritableStream);
}
mic.on('info', (info) => {
console.log(info.toString());
});
mic.on('error', (error) => {
console.error(error);
});
setTimeout(() => {
mic.stopRecording();
}, 3000);
If useDataEmitter is enabled, audio chunks are also emitted through mic.on('data', chunk) in addition to being available from the returned stream.
Invalid option values throw synchronously from the constructor with a TypeError.
new Microphone(options)Creates a new microphone instance.
| Option | Value | Default |
|---|---|---|
endian | 'big' or 'little' | 'little' |
bitwidth | 8, 16, 24, or any value supported by the backend tool | '16' |
encoding | 'signed-integer', 'unsigned-integer', or backend-specific value | 'signed-integer' |
rate | Sample rate supported by the backend tool | '16000' |
channels | Channel count supported by the backend tool | '1' |
fileType | Output container or stream type supported by the backend tool | 'raw' |
device | Input device identifier | Linux: 'plughw:1,0', Windows: 'default', macOS: SoX/CoreAudio device name |
additionalParameters | Raw string arguments appended to the spawn command | false |
spawnOptions | Options object passed to child_process.spawn() except stdio | undefined |
useDataEmitter | Emit audio chunks through the data event | false |
Notes:
arecord -f <format> -t <fileType> -D <device>.rec -t <fileType> -.sox -t waveaudio <device> ... -t <fileType> -.device is provided, the package passes it through SoX's AUDIODEV environment variable.spawnOptions.stdio is intentionally rejected because the library depends on piped stdout and stderr.startRecording()Starts the recording process and returns the spawned process stdout stream. If recording is already active, it returns undefined.
stopRecording()Stops the spawned recording process and clears the internal process reference.
info: stderr output from the recording command as a Buffererror: process or stream errorclose: emitted when the recording process closesdata: stdout audio chunk as a Buffer when useDataEmitter is enabledimport Microphone = require('node-microphone');
const mic = new Microphone({
rate: 16000,
channels: 1,
fileType: 'wav',
});
mic.on('close', (code, signal) => {
console.log(code, signal);
});
npm test
The test suite covers Linux, macOS, and Windows command construction using mocked child processes.
Thanks to ashishbajaj99 and vincentsaluzzo for related microphone modules that helped shape this package.
MIT. See LICENSE.
FAQs
Microphone access in Node.js using arecord on Linux and SoX on Windows/macOS.
The npm package node-microphone receives a total of 432 weekly downloads. As such, node-microphone popularity was classified as not popular.
We found that node-microphone demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.