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

@animaker/macos-audio-devices

v1.3.0

Published

Get, set and configure the audio devices on macOS

Downloads

3

Readme

macos-audio-devices Actions Status

Get, set and configure the audio devices on macOS

Requires macOS 10.12 or later. macOS 10.13 or earlier needs to download the Swift runtime support libraries.

Run as CLI

Using npx

$ npx macos-audio-devices

Installing

$ npm install -g macos-audio-devices
$ audio-devices

Usage

Usage: audio-devices <command> [options]

Groups:
  output          Get or set the default output device
  input           Get or set the default input device
  system          Get or set the default device for system sounds
  volume          Get or set the volume of an output device
  aggregate       Create or delete aggregate audio devices

Commands:
  list            List the available audio devices
  get             Get a device by its ID
  help            Prints help information

Node API

Installation

$ npm install macos-audio-devices

Usage

const audioDevices = require('macos-audio-devices');

const outputDevices = audioDevices.getOutputDevices.sync();
const targetDevice = outputDevices[0];

const defaultDevice = audioDevices.getDefaultOutputDevice.sync();

if (defaultDevice.id !== targetDevice.id) {
  setDefaultOutputDevice(targetDevice.id)
}

if (targetDevice.hasVolume) {
  setOutputDeviceVolume(targetDevice.id, 0.5); // 50%
}

API

Device

id: number

The unique ID of the device.

uid: string

The UID of the device for the AVCaptureDevice API.

name: string

The human readable name of the device.

isOutput: bool

Whether the device is an output device.

isInput: bool

Whether the device is an input device.

volume: number

A number between 0 and 1 representing the volume setting of the device. Only applicable on output devices that support it. It will be undefined otherwise.

transportType: TransportType

The value of this property represents the transport type of the device (USB, PCI, etc).

TransportType: string

Can be one of:

  • avb
  • aggregate
  • airplay
  • autoaggregate
  • bluetooth
  • bluetoothle
  • builtin
  • displayport
  • firewire
  • hdmi
  • pci
  • thunderbolt
  • usb
  • virtual
  • unknown

Sync

Each method described below is asynchronous, but can be called synchronously, by calling .sync on it instead. For example:

getDevice(73).then(device => {…}); // async

const device = getDevice.sync(73); // sync

getAllDevices(): Promise<Device[]>

Get all the audio devices.

getOutputDevices(): Promise<Device[]>

Get all the output devices.

getInputDevices(): Promise<Device[]>

Get all the input devices.

getDevice(deviceId: number): Promise<Device>

Get an audio device by its ID.

deviceId: number

The unique ID of the device.

getDefaultOutputDevice(): Promise<Device>

Get all the default output device.

getDefaultInputDevice(): Promise<Device>

Get all the default input device.

getDefaultSystemDevice(): Promise<Device>

Get all the default input device.

setDefaultOutputDevice(deviceId: number): Promise<void>

Set the default output device.

deviceId: number

The unique ID of an output device.

setDefaultInputDevice(deviceId: number): Promise<void>

Set the default input device.

deviceId: number

The unique ID of an input device.

setDefaultSystemDevice(deviceId: number): Promise<void>

Set the default input device. Can only be an output device.

deviceId: number

The unique ID of an output device.

getOutputDeviceVolume(deviceId: number): Promise<void>

Get the volume level of an output device that supports it.

Throws an error if the device is not an output device or if it doesn't support volume.

deviceId: number

The unique ID of the supported output device.

setOutputDeviceVolume(deviceId: number, volume: number): Promise<void>

Set the volume level of an output device that supports it.

Throws an error if the device is not an output device or if it doesn't support volume.

deviceId: number

The unique ID of the supported output device.

volume: number

The volume level to set the device to. Must be between 0 and 1, otherwise and error will be thrown.

createAggregateDevice(name: string, mainDeviceId: number, otherDeviceIds: number[], options: object): Promise<Device>

Create an aggregate device from other existing devices.

Note that aggregate devices do not support volume, so make sure to update the volume on the devices used to create it instead.

name: string

Human-readable name for the new device.

mainDeviceId: number

The unique ID of the main device.

otherDeviceIds: number[]

An array od unique IDs of the rest of the devices. Needs to have at least one.

options: object
options.multiOutput: boolean

Whether or not to create a Multi-Output Device.

If this is enabled, all the devices need to be output devices.

destroyAggregateDevice(deviceId: number): Promise<void>

Destroy an aggregate device.

deviceId: number

The unique ID of an aggregate device.

Contributing

If you want to use this and need more features or find a bug, please open an issue and I'll do my best to implement.

PRs are always welcome as well 😃