STAudioFormat
Describes requested audio encoding, sample rate, channels, and codec-specific settings.
Declaration
public struct STAudioFormat: Sendable {
public var formatID: STAudioFormatID?
public var commonFormat: STAudioCommonFormat?
public var sampleRate: Int?
public var channelCount: Int?
public var encoderBitsPerSample: Int?
public var encoderBitRate: Int?
public init(
formatID: STAudioFormatID? = nil,
commonFormat: STAudioCommonFormat? = nil,
sampleRate: Int? = nil,
channelCount: Int? = nil,
encoderBitsPerSample: Int? = nil,
encoderBitRate: Int? = nil
)
}
Overview
STAudioFormat configures the requested audio encoding and sample characteristics for recording audio to a file or URL. It combines an optional codec identifier, PCM sample representation, sample rate, channel count, and encoder-specific settings. The recording destination/container is selected separately; not every codec and container combination is supported.
Purpose and usage
Describe audio encoding, sample representation, sample rate and channel count. Pass this value in an audio configuration parameter that exposes an `STAudioFormat` property.
Properties
formatID— Declared asSTAudioFormatID.commonFormat— Declared asSTAudioCommonFormat.sampleRate— Declared as Int.channelCount— Declared as Int.encoderBitsPerSample— Declared as Int.encoderBitRate— Declared as Int.
Swift example
public struct STAudioFormat: Sendable {
public var formatID: STAudioFormatID?
public var commonFormat: STAudioCommonFormat?
public var sampleRate: Int?
public var channelCount: Int?
public var encoderBitsPerSample: Int?
public var encoderBitRate: Int?
public init(
formatID: STAudioFormatID? = nil,
commonFormat: STAudioCommonFormat? = nil,
sampleRate: Int? = nil,
channelCount: Int? = nil,
encoderBitsPerSample: Int? = nil,
encoderBitRate: Int? = nil
)
}
Encoder-specific settings
encoderBitsPerSample — Encoder bit depth for ALAC (Apple Lossless). Supported values are 16, 20, 24, and 32 bits.
encoderBitRate — Encoder bit rate in bits per second for AAC.
These optional values are codec-specific. Setting the AAC bit rate does not configure ALAC bit depth, and setting ALAC bit depth does not configure AAC bit rate. An omitted value leaves that parameter unspecified; do not assume an unverified numeric default.
let alac = STAudioFormat(
formatID: .alac,
encoderBitsPerSample: 24
)
let aac = STAudioFormat(
formatID: .aac,
encoderBitRate: 128000
)