Skip to content

touchifyapp/node-cpvc

Repository files navigation

@touchifyapp/cpvc (Cross-Platform Volume Control)

https://github.com/touchifyapp/node-cpvc/actions

Cross platform module for interacting with Audio Devices and handling System Audio. Node bindings for the cpvc crate.

Compatibility

  • Windows
  • Mac OS X
  • Linux (PulseAudio only)

Important
cpvc requires PulseAudio server to work on Linux.

Prebuilt binaries

Platform arch
Windows x64
Windows x86
Windows arm64
macOS x64
macOS arm64
Linux x64 (gnu)
Linux x64 (musl)
Linux arm (gnu)
Linux arm64 (musl)
FreeBSD x64

Note: To build package from source, libasound2-dev and libpulse-dev libraries are required. (eg. sudo apt install libasound2-dev libpulse-dev).

Installation

# npm
npm i @touchifyapp/cpvc

# pnpm
pnpm add @touchifyapp/cpvc

#yarn
yarn add @touchifyapp/cpvc

Usage

import { getSoundDevices, getMute, setMute, getSystemVolume, setSystemVolume } from "../index.js";

// get system sound devices names
const devices = getSoundDevices();
console.log(devices); // prints ['devicename']

// check whether the system is muted
const muted = getMute();
console.log("is muted:", muted); // prints is muted: false

// set whether the system is muted
setMute(true);
const muted = getMute();
console.log("is muted:", muted); // prints is muted: true

// get current system volume
const volume = getSystemVolume();
console.log("volume:", volume); // prints volume: 30

// set system volume
setSystemVolume(50);
const volume = getSystemVolume();
console.log("volume:", volume); // prints volume: 50

Contribute

Prerequistes

  • Install the latest Rust
  • Install Node.js@20+ which fully supported Node-API
  • Run corepack enable

Getting started

# clone repository
git clone https://github.com/touchifyapp/node-cpvc
cd node-cpvc

# install packages
pnpm i

# build and test
pnpm build
pnpm test

Build

After pnpm build command, you can see cpvc.[darwin|win32|linux].node file in project root. This is the native addon built from lib.rs.

Test

Run pnpm test to testing native addon.

Note: a build is necessary before running pnpm test if changes were applied on the rust code.

CI

With GitHub Actions, each commit and pull request will be built and tested automatically in [node@20, node@22, node@24] x [macOS, Linux, Windows] matrix.

LICENSE

MIT

About

Cross platform module for interacting with Audio Devices and handling System Audio.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors