Thanks to the help of Apple DTS engineers, there are two workarounds:
Quoting them directly:
This hasn't made it back to you, but there are two workaround which added to your bug which should eventually be sent back to you. Those are:
Option 1:
Annotate tapBlock enclosure as @Sendable
Isolate the call of `self?.processAudioBuffer(buffer)
However, since AVAudioBuffer is not marked as sendable, either import AVFAudio.AVAudioBuffer or AVFoundation with @preconcurrency annotation:
@preconcurrency import AVFAudio.AVAudioBuffer // or @preconcurrency import AVFoundation
[…]
engine.mainMixerNode.installTap(onBus: 0, bufferSize: 1024, format: format) { @Sendable [weak self] buffer, _ in
Task { @MainActor in
self?.processAudioBuffer(buffer)
}
}
Option 2:
To avoid annotating the import with @preconcurrency
Annotate tapBlock enclosure as @Sendable
Extract data from AVAudioBuffer within the closure
Isolate the call of `self?.processAudioData(array)
engine.mainMixerNode.installTap(onBus: 0, bufferSize: 1024, format: format) { @Sendable [weak self] buffer, _ in
// Extract the data from the buffer
guard let channelData = buffer.floatChannelData?[0] else { return }
let frameCount = Int(buffer.frameLength)
let audioData = Array(UnsafeBufferPointer(start: channelData, count: frameCount))
Task { @MainActor in
self?.processAudioData(audioData)
}
}