package audio // Device is one audio endpoint (a capture input or a render output). // // ID is whatever the platform calls the endpoint and is PERSISTED in settings: // a WASAPI endpoint id on Windows, a PulseAudio source/sink name on Linux. // It is opaque to everything above this package, which only ever hands it back. type Device struct { ID string `json:"id"` // opaque platform endpoint id (persisted) Name string `json:"name"` // friendly name shown in dropdowns Default bool `json:"default"` // is this the system default endpoint } // DeviceName resolves an endpoint id to its friendly name. // // Diagnostics quote the id that was CONFIGURED, which is a GUID — an operator // told "no audio at all from {0.0.1.00000000}.{6a27abfd…}" learns nothing they // can act on, while "no audio at all from DAX RX 1 (FlexRadio DAX)" points // straight at the DAX panel. // // Falls back to the id when the endpoint cannot be found, which is itself worth // seeing: a device that has disappeared explains an empty recording too. func DeviceName(id string) string { if id == "" { return "(none)" } for _, list := range []func() ([]Device, error){ListInputDevices, ListOutputDevices} { devs, err := list() if err != nil { continue } for _, d := range devs { if d.ID == id { return d.Name } } } return id }