• Stars
    star
    165
  • Rank 228,906 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Get, set and configure the Audio Devices on macOS

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 πŸ˜ƒ

More Repositories

1

macos-key-cast

Log keys pressed on macOS. Useful for screen recordings and presentations.
Swift
255
star
2

mac-screen-capture-permissions

Check and request permission to capture the screen
JavaScript
117
star
3

electron-builder-notarize

Notarize Electron applications using electron-builder
JavaScript
80
star
4

macos-manage-apps

Launch and terminate apps on macOS
Swift
60
star
5

mac-open-with

Open a file with an installed app on macOS
Swift
47
star
6

ink-scrollbar

Scrollbar Component for Ink
JavaScript
40
star
7

kap-recording-time

Show time elapsed while recording
Swift
36
star
8

mac-windows

Provide Information about Application Windows running
Swift
35
star
9

kap-soundflower

Record the system audio using Soundflower
JavaScript
28
star
10

ink-multi-select

Multi select input component for Ink
JavaScript
26
star
11

now-integration

A framework that allows better code structure and routing for ZEIT Integrations
TypeScript
23
star
12

kap-key-cast

Log keys pressed while recording
JavaScript
20
star
13

react-better-password

Password input for ReactJS that mimics mobile password masking behavior
JavaScript
19
star
14

kap-hide-clock

JavaScript
17
star
15

mac-focus-window

Focus a window and bring it to the front on macOS
Swift
15
star
16

kap-playback-speed

Speed up or slow down Kap recordings
JavaScript
14
star
17

kap-camera

JavaScript
14
star
18

macos-accessibility-permissions

Log keys pressed on macOS. Useful for screen recordings and presentations.
JavaScript
10
star
19

hide-desktop-icons

Hide the desktop icons for macOS
Swift
9
star
20

kap-dropbox

Upload recordings to Dropbox
JavaScript
9
star
21

ink-select

Select Component for Ink
JavaScript
7
star
22

kap-recording-name

Create meaningful names for your recordings
JavaScript
5
star
23

ink-aligned

Align Components horizontally for Ink
JavaScript
3
star
24

electron-builder-notarize-pkg

JavaScript
2
star
25

kap-hide-desktop-icons

JavaScript
2
star
26

kap-progress-bar

Add a progress bar to your recordings
JavaScript
2
star
27

now-storyblok

Storyblok integration for ZEIT's Now
TypeScript
2
star
28

kap-do-not-disturb

Silence notifications while recording
JavaScript
2
star
29

now-pusher

Pusher integration for ZEIT's Now
TypeScript
2
star
30

hide-desktop-icons-cli

Clean your desktop by temporarily hiding your icons
JavaScript
2
star
31

test

something
1
star
32

duty-pick-web

A static ReactJS app to utilize the duty-pick API
JavaScript
1
star
33

SpaceShips

A SpaceShip shooting game written in Java using swing and awt
Java
1
star
34

Resume

Resume Website
CSS
1
star
35

kap-reverse

Reverse Kap recordings
JavaScript
1
star
36

crypto-des

Step by step DES algorithm
JavaScript
1
star
37

SmartChecklist

Dynamic checklist that handles and adapts to exceptions
JavaScript
1
star
38

generator-ez-react-component

An easy generator for react components
1
star