Gathering detailed insights and metrics for naudiodon
Gathering detailed insights and metrics for naudiodon
Gathering detailed insights and metrics for naudiodon
Gathering detailed insights and metrics for naudiodon
npm install naudiodon
Typescript
Module System
Node Version
NPM Version
71.9
Supply Chain
98.9
Quality
75.7
Maintenance
100
Vulnerability
100
License
C++ (46.91%)
C (42.12%)
JavaScript (8.08%)
Python (2.85%)
Batchfile (0.05%)
Total Downloads
54,490
Last Day
14
Last Week
276
Last Month
1,249
Last Year
8,975
Apache-2.0 License
312 Stars
170 Commits
87 Forks
9 Watchers
2 Branches
Updated on Jul 14, 2025
Latest Version
2.3.6
Package Id
naudiodon@2.3.6
Unpacked Size
1.55 MB
Size
581.54 kB
File Count
37
NPM Version
8.1.2
Node Version
16.13.0
Cumulative downloads
Total Downloads
Last Day
-60%
14
Compared to previous day
Last Week
-27.4%
276
Compared to previous week
Last Month
37.4%
1,249
Compared to previous month
Last Year
30.3%
8,975
Compared to previous year
2
1
A Node.js addon that provides a wrapper around the PortAudio library, enabling an application to record and play audio with cross platform support. With this library, you can create node.js streams that can be piped to or from other streams, such as files and network connections. This library supports back-pressure.
This is a fork of node-portaudio, refactored by:
Little of the original remains but I am very grateful for Joe Ferner for the inspiration and framework to get started.
This library has been tested on MacOS X 10.11, Windows 10, Linux Ubuntu Trusty and Raspbian Jessie (armhf
architecture).
Note: This is a server side library. It is not intended as a means to play and record audio via a browser.
Install Node.js for your platform and make sure that node is able to build native modules with node-gyp. This software has been developed against the long term stable (LTS) release. For ease of installation with other node packages, this package includes a copy of the dependent PortAudio library and so has no prerequisites.
Naudiodon is designed to be require
d to use from your own application to provide async processing. For example:
npm install naudiodon
For Raspberry Pi users, please note that this library is not intended for use with the internal sound card. Please use an external USB sound card or GPIO breakout board such as the Pi-DAC+ Full-HD Audio Card.
To get list of supported devices, call the getDevices()
function.
1var portAudio = require('naudiodon'); 2 3console.log(portAudio.getDevices());
An example of the output is:
1[ { id: 0, 2 name: 'Built-in Microph', 3 maxInputChannels: 2, 4 maxOutputChannels: 0, 5 defaultSampleRate: 44100, 6 defaultLowInputLatency: 0.00199546485260771, 7 defaultLowOutputLatency: 0.01, 8 defaultHighInputLatency: 0.012154195011337868, 9 defaultHighOutputLatency: 0.1, 10 hostAPIName: 'Core Audio' }, 11 { id: 1, 12 name: 'Built-in Input', 13 maxInputChannels: 2, 14 maxOutputChannels: 0, 15 defaultSampleRate: 44100, 16 defaultLowInputLatency: 0.00199546485260771, 17 defaultLowOutputLatency: 0.01, 18 defaultHighInputLatency: 0.012154195011337868, 19 defaultHighOutputLatency: 0.1, 20 hostAPIName: 'Core Audio' }, 21 { id: 2, 22 name: 'Built-in Output', 23 maxInputChannels: 0, 24 maxOutputChannels: 2, 25 defaultSampleRate: 44100, 26 defaultLowInputLatency: 0.01, 27 defaultLowOutputLatency: 0.002108843537414966, 28 defaultHighInputLatency: 0.1, 29 defaultHighOutputLatency: 0.012267573696145125, 30 hostAPIName: 'Core Audio' } ]
Note that the device id
parameter index value can be used as to specify which device to use for playback or recording with optional parameter deviceId
.
To get list of host APIs, call the getHostAPIs()
function.
1var portAudio = require('naudiodon'); 2 3console.log(portAudio.getHostAPIs());
An example of the output is:
1{ defaultHostAPI: 0, 2 HostAPIs: 3 [ { id: 0, 4 name: 'MME', 5 deviceCount: 8, 6 defaultInput: 1, 7 defaultOutput: 5 }, 8 { /* ... */ } ] }
Note that the defaultInput
and defaultOutput
values can be used as to specify which device to use for playback or recording with optional parameter deviceId
.
Playing audio involves streaming audio data to a new instance of AudioIO
configured with outOptions
- which returns a Node.js Writable Stream:
1const fs = require('fs'); 2const portAudio = require('naudiodon'); 3 4// Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream 5var ao = new portAudio.AudioIO({ 6 outOptions: { 7 channelCount: 2, 8 sampleFormat: portAudio.SampleFormat16Bit, 9 sampleRate: 48000, 10 deviceId: -1, // Use -1 or omit the deviceId to select the default device 11 closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error 12 } 13}); 14 15// Create a stream to pipe into the AudioOutput 16// Note that this does not strip the WAV header so a click will be heard at the beginning 17var rs = fs.createReadStream('steam_48000.wav'); 18 19// Start piping data and start streaming 20rs.pipe(ao); 21ao.start();
Recording audio involves streaming audio data from a new instance of AudioIO
configured with inOptions
- which returns a Node.js Readable Stream:
1var fs = require('fs'); 2var portAudio = require('../index.js'); 3 4// Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream 5var ai = new portAudio.AudioIO({ 6 inOptions: { 7 channelCount: 2, 8 sampleFormat: portAudio.SampleFormat16Bit, 9 sampleRate: 44100, 10 deviceId: -1, // Use -1 or omit the deviceId to select the default device 11 closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error 12 } 13}); 14 15// Create a write stream to write out to a raw audio file 16var ws = fs.createWriteStream('rawAudio.raw'); 17 18//Start streaming 19ai.pipe(ws); 20ai.start(); 21
Note that this produces a raw audio file - wav headers would be required to create a wav file. However this basic example produces a file may be read by audio software such as Audacity, using the sample rate and format parameters set when establishing the stream.
There is an additional "timestamp"
property available on the buffers that are streamed from the input which represents a time value for the first sample in the returned buffer. It can be accessed as follows:
1ai.on('data', buf => console.log(buf.timestamp));
To stop the recording, call ai.quit()
. For example:
1process.on('SIGINT', () => { 2 console.log('Received SIGINT. Stopping recording.'); 3 ai.quit(); 4});
A bi-directional audio stream is available by creating an instance of AudioIO
configured with both inOptions
and outOptions
- which returns a Node.js Duplex stream:
1var portAudio = require('../index.js'); 2 3// Create an instance of AudioIO with inOptions and outOptions, which will return a DuplexStream 4var aio = new portAudio.AudioIO({ 5 inOptions: { 6 channelCount: 2, 7 sampleFormat: portAudio.SampleFormat16Bit, 8 sampleRate: 44100, 9 deviceId: -1 // Use -1 or omit the deviceId to select the default device 10 }, 11 outOptions: { 12 channelCount: 2, 13 sampleFormat: portAudio.SampleFormat16Bit, 14 sampleRate: 44100, 15 deviceId: -1 // Use -1 or omit the deviceId to select the default device 16 } 17}); 18 19aio.start();
Ensure that when you compile portaudio that the configure scripts says "ALSA" yes.
You may see or have seen the following message during initilisation of the audio library on MacOS:
WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager
for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host
incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
A locally compiled version of the portaudio library is now included with the latest version of naudiodon that uses more up-to-date APIs from Apple. The portaudio team are aware of this issue.
Optimisation is still required for use with lower specification devices, such as Raspberry Pis.
Although the architecture of naudiodon is such that it could be used at scale in production environments, development is not yet complete. In its current state, it is recommended that this software is used in development environments and for building prototypes. Future development will make this more appropriate for production use.
Contributions can be made via pull requests and will be considered by the author on their merits. Enhancement requests and bug reports should be raised as github issues. For support, please contact Streampunk Media.
This software is released under the Apache 2.0 license. Copyright 2017 Streampunk Media Ltd.
This software uses libraries from the PortAudio project. The license terms for PortAudio are stated to be an MIT license. Streampunk Media are grateful to Ross Bencina and Phil Burk for their excellent library.
No vulnerabilities found.