coreaudio

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

coreaudio

Names the machine's audio devices, in pure Go with CGO_ENABLED=0, so a program can send its sound somewhere in particular instead of wherever the system happens to be pointing.

devs, err := coreaudio.Devices()
for _, d := range devs {
    fmt.Println(d) // "VITURE" [1 out] 0ED43331-0000-0000-2021-010380100A78
}

out, err := coreaudio.DefaultOutput()
fmt.Println("sound is going to", out.Name)

The need is ordinary and the default is wrong often enough to matter. A film played on a pair of XR glasses draws its picture on the glasses and, with no device named, plays its sound out of the Mac's own speakers. Nothing reports an error, because nothing went wrong: the sound went to the default output, which is not where the person is looking.

Device.UID is the string AVFoundation and AudioQueue both take to be told where to play, and it keeps identifying the device after a reboot or a re-plug, unlike the numeric ids beside it, which do not.

Capture devices are listed too. Filtering them out here would leave a caller looking for a device by name unable to tell no such device from a device by that name that cannot play, and those call for different words.

Everything is bound through purego: no cgo, no Xcode, and the package cross-compiles.

Documentation

Overview

Package coreaudio names the machine's audio devices, so a program can send its sound somewhere in particular instead of wherever the system happens to be pointing.

The need is ordinary and the default is wrong often enough to matter: a film played on a pair of XR glasses draws its picture on the glasses and, with no device named, plays its sound out of the Mac's own speakers. Nothing reports an error, because nothing went wrong -- the sound simply went to the default output, which is not where the person is looking.

What is here is enumeration and identity, not playback. A device's Device.UID is the string AVFoundation and AudioQueue both take to be told where to play, and it is stable across reboots and re-plugs, unlike the numeric ids beside it, which are not.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("coreaudio: only macOS has CoreAudio")

ErrUnsupported is returned by every call off macOS. CoreAudio is a macOS framework; there is nothing here to fall back to, and pretending otherwise would hand a caller an empty device list that looks like a machine with no sound card.

Functions

This section is empty.

Types

type Device

type Device struct {
	// UID identifies the device to the rest of CoreAudio, and keeps identifying
	// it after a reboot or a re-plug. It is what a setting should store; the
	// name is what a person should read.
	UID string
	// Name is the name shown in Sound settings.
	Name string
	// Outputs is how many output streams the device publishes, and Inputs how
	// many input ones. A device is not necessarily either: a microphone has no
	// outputs, and asking it to play sound would fail for a reason nobody would
	// guess from "device not found".
	Outputs, Inputs int
}

Device is one audio device the system knows about.

func DefaultOutput

func DefaultOutput() (Device, error)

DefaultOutput reports ErrUnsupported.

func Devices

func Devices() ([]Device, error)

Devices reports ErrUnsupported.

func (Device) CanPlay

func (d Device) CanPlay() bool

CanPlay reports whether the device has anywhere to put sound.

func (Device) String

func (d Device) String() string

String renders the device the way a listing reads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL