# Audio pipeline Module: `VorleserAudio`. It depends only on AVFoundation. It knows nothing about Ollama or text. ## Interface ```swift public struct AudioChunk: Sendable { public let epoch: UInt64 public let segmentID: Int public let samples: [Float] // mono, 24 kHz, already converted from Int16 public let isLastOfSegment: Bool } public enum AudioEvent: Sendable { case segmentStarted(epoch: UInt64, segmentID: Int) case segmentFinished(epoch: UInt64, segmentID: Int) case starved(epoch: UInt64) // nothing left scheduled, not finished case routeChanged // engine reconfigured; session should re-seek case failed(String) } public protocol AudioPlaying: AnyObject, Sendable { var events: AsyncStream { get } func schedule(_ chunk: AudioChunk) func play() throws func pause() func stopAndFlush() // drops everything scheduled func setRate(_ rate: Float) // 0.5 ... 2.0 func elapsedInCurrentSegment() -> TimeInterval? } ``` A `FakeAudioPlayer` that records calls and emits events on demand must exist in the test target from M3 onwards. `ReadingSession` tests run against it. ## Graph ``` AVAudioPlayerNode ──▶ AVAudioUnitTimePitch ──▶ engine.mainMixerNode ──▶ outputNode format: Float32, 24_000 Hz, 1 ch, non-interleaved ``` - Connect player → timePitch with the 24 kHz mono format. The mixer handles sample-rate conversion to the device rate. - `timePitch.rate = playbackRate` (0.5–2.0). `timePitch.pitch = 0`. Rate changes apply live without rescheduling. - `timePitch.overlap` default (8). If the speech sounds phasey at 1.5–2.0×, increase it and evaluate. ## PCM conversion ```swift // data: PCM16LE bytes, even length guaranteed by the client let count = data.count / 2 var floats = [Float](repeating: 0, count: count) data.withUnsafeBytes { raw in let src = raw.bindMemory(to: Int16.self) for i in 0..