### Example Output of getDevices() Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md This is an example of the structure of the device list returned by `getDevices()`. ```javascript [ { id: 0, name: 'Built-in Microph', maxInputChannels: 2, maxOutputChannels: 0, defaultSampleRate: 44100, defaultLowInputLatency: 0.00199546485260771, defaultLowOutputLatency: 0.01, defaultHighInputLatency: 0.012154195011337868, defaultHighOutputLatency: 0.1, hostAPIName: 'Core Audio' }, { id: 1, name: 'Built-in Input', maxInputChannels: 2, maxOutputChannels: 0, defaultSampleRate: 44100, defaultLowInputLatency: 0.00199546485260771, defaultLowOutputLatency: 0.01, defaultHighInputLatency: 0.012154195011337868, defaultHighOutputLatency: 0.1, hostAPIName: 'Core Audio' }, { id: 2, name: 'Built-in Output', maxInputChannels: 0, maxOutputChannels: 2, defaultSampleRate: 44100, defaultLowInputLatency: 0.01, defaultLowOutputLatency: 0.002108843537414966, defaultHighInputLatency: 0.1, defaultHighOutputLatency: 0.012267573696145125, hostAPIName: 'Core Audio' } ] ``` -------------------------------- ### Install Naudiodon Package Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Install the Naudiodon package using npm. This command installs the library and its dependencies. ```bash npm install naudiodon ``` -------------------------------- ### Example Output of getHostAPIs() Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md This is an example of the structure of the host APIs list returned by `getHostAPIs()`. ```javascript { defaultHostAPI: 0, HostAPIs: [ { id: 0, name: 'MME', deviceCount: 8, defaultInput: 1, defaultOutput: 5 }, { /* ... */ } ] } ``` -------------------------------- ### Record Audio with AudioIO Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Create an `AudioIO` instance with `inOptions` to record audio. This returns a Node.js Readable Stream. Pipe this stream to a writable stream (e.g., `fs.createWriteStream`) and call `start()`. ```javascript var fs = require('fs'); var portAudio = require('../index.js'); // Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream var ai = new portAudio.AudioIO({ inOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 44100, deviceId: -1, // Use -1 or omit the deviceId to select the default device closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error } }); // Create a write stream to write out to a raw audio file var ws = fs.createWriteStream('rawAudio.raw'); //Start streaming ai.pipe(ws); ai.start(); ``` -------------------------------- ### Play Audio with AudioIO Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Create an `AudioIO` instance with `outOptions` to play audio. This returns a Node.js Writable Stream. Pipe a readable stream (e.g., from `fs.createReadStream`) into it and call `start()`. ```javascript const fs = require('fs'); const portAudio = require('naudiodon'); // Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream var ao = new portAudio.AudioIO({ outOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 48000, deviceId: -1, // Use -1 or omit the deviceId to select the default device closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error } }); // Create a stream to pipe into the AudioOutput // Note that this does not strip the WAV header so a click will be heard at the beginning var rs = fs.createReadStream('steam_48000.wav'); // Start piping data and start streaming rs.pipe(ao); ao.start(); ``` -------------------------------- ### Stop Recording with ai.quit() Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md To stop the recording process, call the `ai.quit()` method. This example shows how to trigger it on a SIGINT signal. ```javascript process.on('SIGINT', () => { console.log('Received SIGINT. Stopping recording.'); ai.quit(); }); ``` -------------------------------- ### List Host APIs Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Call `getHostAPIs()` to retrieve a list of supported host APIs. The `defaultInput` and `defaultOutput` values can specify devices for playback or recording. ```javascript var portAudio = require('naudiodon'); console.log(portAudio.getHostAPIs()); ``` -------------------------------- ### Copy PortAudio dylib to Project Directory Source: https://github.com/csukuangfj/naudiodon2/blob/master/portaudio/mac-build.txt Copies the built PortAudio dynamic library to a specific location within the project. This is typically done after a successful build. ```bash cp libs/.libs/libportaudio.dylib ../naudiodon/portaudio/bin/ ``` -------------------------------- ### Configure PortAudio with macOS Deployment Target Source: https://github.com/csukuangfj/naudiodon2/blob/master/portaudio/mac-build.txt Sets the minimum macOS version for the build. This is a common step for ensuring compatibility with older macOS versions. ```bash ./configure MACOSX_DEPLOYMENT_TARGET=10.6 ``` -------------------------------- ### List Audio Devices Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Call `getDevices()` to retrieve a list of supported audio devices. The `id` parameter can be used to select a specific device. ```javascript var portAudio = require('naudiodon'); console.log(portAudio.getDevices()); ``` -------------------------------- ### Create Bi-directional Audio Stream Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md Instantiate AudioIO with both input and output options to create a Node.js Duplex stream for bi-directional audio. Ensure correct channel count, sample format, and sample rate are configured. ```javascript var portAudio = require('../index.js'); // Create an instance of AudioIO with inOptions and outOptions, which will return a DuplexStream var aio = new portAudio.AudioIO({ inOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 44100, deviceId: -1 // Use -1 or omit the deviceId to select the default device }, outOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 44100, deviceId: -1 // Use -1 or omit the deviceId to select the default device } }); aio.start(); ``` -------------------------------- ### Set Library ID with install_name_tool Source: https://github.com/csukuangfj/naudiodon2/blob/master/portaudio/mac-build.txt Modifies the Mach-O binary to set the internal library ID. This is crucial for dynamic linking and ensuring the system can find the library correctly. ```bash install_name_tool -id @rpath/libportaudio.dylib portaudio/bin/libportaudio.dylib ``` -------------------------------- ### Access Timestamp from Recorded Buffers Source: https://github.com/csukuangfj/naudiodon2/blob/master/README.md The buffers streamed from the input have a `timestamp` property representing the time of the first sample. Access it via the 'data' event. ```javascript ai.on('data', buf => console.log(buf.timestamp)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.