STAudioRouteInfo
A cross-platform snapshot of currently selected audio input and output endpoints.
Overview
STAudioRouteInfo is a Sendable snapshot of audio routing, suitable for delivering to application code when the active input or output changes. It contains the observed timestamp, output and input endpoints, an optional route-change reason, and a convenient first-output accessor. It does not itself select or change the audio route.
Declaration
public struct STAudioRouteInfo: Sendable, CustomStringConvertible {
public var timestamp: Date
public var outputs: [STEndpoint]
public var inputs: [STEndpoint]
public var reason: String?
public var primaryOutput: STEndpoint? { get }
public init(timestamp: Date = Date(), outputs: [STEndpoint], inputs: [STEndpoint], reason: String? = nil)
}
Properties
timestamp — Date when the route snapshot was observed; defaults to Date() in the initializer.
outputs — Selected output endpoints; can contain more than one endpoint.
inputs — Selected input endpoints.
reason — Optional route-change reason, when provided by the platform.
primaryOutput — Returns outputs.first, or nil when outputs is empty. It does not actively choose a device.
Nested type: STAudioRouteInfo.Endpoint
STEndpoint is a public Sendable, Hashable structure describing one input or output. Its public properties are name: String, uid: String?, kind: String?, manufacturer: String?, transportDescription: String?, isBluetooth: Bool?, nominalSampleRate: Double?, and channels: UInt32?. Only name is required by its public initializer; other values default to nil.
On macOS, STEndpoint additionally exposes deviceID: UInt32? and transportType: UInt32? for CoreAudio device identity and transport information. Both are initialized to nil by the public initializer and can be populated later. These properties are not available on iOS-family platforms.
Optional endpoint properties can be absent; applications should not assume that a transport label, Bluetooth flag, sample rate, or channel count is always available.
public struct STEndpoint: Sendable, Hashable, CustomStringConvertible {
public var name: String
public var uid: String?
public var kind: String?
public var manufacturer: String?
public var transportDescription: String?
public var isBluetooth: Bool?
public var nominalSampleRate: Double?
public var channels: UInt32?
// macOS only: deviceID: UInt32?, transportType: UInt32?
}
Handling an audio route event
Use the .audioRoute case of STMediaEventData to extract this snapshot. For device-change notifications, STAudioDeviceEventData.routeInfo provides the same type.
switch event.data {
case .audioRoute(let route):
print(route.outputs.map(\.name))
case .audioDevice(let device):
print(device.routeInfo.primaryOutput?.name ?? "No output")
default:
break
}
Event payload mapping
STMediaEventData.audioRoute carries this structure. Match the associated enum case when handling STMediaEvent.data. The event type and function identify the occurrence; the payload provides its event-specific details.
switch event.data {
case .audioRoute(let route):
print("Outputs: \(route.outputs.map(\.name))")
print("Inputs: \(route.inputs.map(\.name))")
default:
break
}