npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hamitzor/sonance.js

v1.0.1

Published

Access audio I/O from Node

Downloads

2

Readme

Overview

  • Access well-known audio I/O APIs
  • Windows: WASAPI, DirectSound
  • Linux: ALSA, JACK and PulseAudio
  • Probe available audio devices
  • Stream audio to output devices
  • Stream audio from input devices
  • Fully configurable audio streaming, allows configuring
    • sample rate
    • bit depth
    • frame size
    • number of channels
  • The library is implemented fully with Node.js streams
    • Convenient to use with network I/O, file I/O and other streams on Node.js
    • Comes with all the advantages of Node.js streams

Installation

Install it using npm or yarn

npm install @hamitzor/sonance.js

or

yarn add @hamitzor/sonance.js

As simple as that, no additional library/software required for installation. If you run into trouble during installation, don't hesitate to create an issue at Github.

Note Only Windows and Linux are supported at the moment.

Usage

To see some complete examples, you can check out the examples repository.

But here are some simple examples:

Read from microphone

const {
  createAudioInputStream,
  probeDevices,
  LowLevelAudioApi,
} = require("@hamitzor/sonance.js");

// Get the default input device
const { defaultInputDevice } = probeDevices();

// Create a read stream
const audioStream = createAudioInputStream({
  api: LowLevelAudioApi.WASAPI, // On Linux, can be changed to, e.g. ALSA
  deviceId: defaultInputDevice.id, // The device to read from
  channels: 1, // The number of channels
  sampleRate: 48000, // Sample rate
  bufferFrames: 1920, // Frame size: number of samples in a frame
  format: PCMFormat.RTAUDIO_SINT16, // 16-bit signed integer (16-bit depth)
});

// Do whatever you want with the stream

// E.g. read 3840 bytes from it
const data = audioStream.read(3840);

// Or, pass it to a file write stream to save to a file
const { pipeline } = require("stream");
const { createWriteStream } = require("fs");

pipeline(audioStream, createWriteStream("somefile.raw"));

// Or, pass it to a TCP connection to send it over network
const { createWriteStream } = require("fs");

const server = net.createServer((connection) => {
  pipeline(audioStream, connection);
});

// Or do anything you want that is achievable with a readable Node.js stream

Stream audio to output devices

const {
  createAudioOutputStream,
  probeDevices,
  LowLevelAudioApi,
} = require("@hamitzor/sonance.js");

// Get the default output device
const { defaultOutputDevice } = probeDevices();

// Create a write stream
const audioStream = createAudioOutputStream({
  api: LowLevelAudioApi.WASAPI, // On Linux, can be changed to, e.g. ALSA
  deviceId: defaultOutputDevice.id, // The device to stream to
  channels: 1, // The number of channels
  sampleRate: 48000, // Sample rate
  bufferFrames: 1920, // Frame size: number of samples in a frame
  format: PCMFormat.RTAUDIO_SINT16, // 16-bit signed integer (16-bit depth)
});

// Do whatever you want with the stream

// E.g. write 3840 bytes to it
const data = audioStream.write(new Uint8Array(3840).fill(0));

// Or, pass it to a file read stream to playback a file
const { pipeline } = require("stream");
const { createReadStream } = require("fs");

pipeline(createReadStream("somefile.raw"), audioStream);

// Or, pass it to a TCP connection for playback over network
const { createWriteStream } = require("fs");

const server = net.createServer((connection) => {
  pipeline(connection, audioStream);
});

// Or do anything you want that is achievable with a writable Node.js stream

Credits

This packages uses the C++ library named rtaudio under the hood. To check it out, visit https://github.com/thestk/rtaudio.

License

MIT