Audio

The Audio service lists the audio devices and controls the default input and output, the volume and mute, through CoreAudio. Access it via app.audio.

for device in app.audio.devices():
    print(device.name, device.transport, device.is_default_output)

app.audio.set_default_output("AirPods Pro")
app.audio.set_volume(0.3)

A device is named by its uid or its name. Methods that take a device use the default device of the scope when it is omitted; scope is "output" or "input".

Methods

Method Returns Description
devices() list[AudioDevice] Every device: built-in, USB, Bluetooth, AirPlay, virtual...
default_output(), default_input() AudioDevice The devices sound plays through and recording comes from
set_default_output(device), set_default_input(device) None Switch them, by uid or name
volume(device=None, scope="output") float \| None From 0.0 to 1.0, or None for a device with no volume control (some HDMI and digital outputs)
set_volume(value, device=None, scope="output") None Set the volume
is_muted(device=None, scope="output") bool \| None Whether it is muted, or None if it cannot be
set_muted(muted, device=None, scope="output") None Mute or unmute

An unknown device, or a control the device does not allow changing, raises nib.ServiceError.

AudioDevice

Field Type Description
id int CoreAudio's id while it is connected
uid str A stable identifier, the same after a reconnect
name str The name shown in System Settings > Sound
input_channels, output_channels int Recording and playback channels; is_input and is_output say whether they are above 0
is_default_input, is_default_output bool Whether it is a default
transport str "builtIn", "usb", "bluetooth", "hdmi", "displayPort", "airPlay", "thunderbolt", "virtual", "aggregate" or "other"