fix(ios): avoid actor-isolated access from audio tap
This commit is contained in:
@@ -2,7 +2,7 @@ import AVFAudio
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Speech
|
import Speech
|
||||||
|
|
||||||
private func makeAudioTapEnqueueCallback(queue: AudioBufferQueue) -> AVAudioNodeTapBlock {
|
private func makeAudioTapEnqueueCallback(queue: AudioBufferQueue) -> @Sendable (AVAudioPCMBuffer, AVAudioTime) -> Void {
|
||||||
{ buffer, _ in
|
{ buffer, _ in
|
||||||
// This callback is invoked on a realtime audio thread/queue. Keep it tiny and nonisolated.
|
// This callback is invoked on a realtime audio thread/queue. Keep it tiny and nonisolated.
|
||||||
queue.enqueueCopy(of: buffer)
|
queue.enqueueCopy(of: buffer)
|
||||||
@@ -183,11 +183,12 @@ final class VoiceWakeManager: NSObject, ObservableObject {
|
|||||||
|
|
||||||
let queue = AudioBufferQueue()
|
let queue = AudioBufferQueue()
|
||||||
self.tapQueue = queue
|
self.tapQueue = queue
|
||||||
|
let tapBlock: @Sendable (AVAudioPCMBuffer, AVAudioTime) -> Void = makeAudioTapEnqueueCallback(queue: queue)
|
||||||
inputNode.installTap(
|
inputNode.installTap(
|
||||||
onBus: 0,
|
onBus: 0,
|
||||||
bufferSize: 1024,
|
bufferSize: 1024,
|
||||||
format: recordingFormat,
|
format: recordingFormat,
|
||||||
block: makeAudioTapEnqueueCallback(queue: queue))
|
block: tapBlock)
|
||||||
|
|
||||||
self.audioEngine.prepare()
|
self.audioEngine.prepare()
|
||||||
try self.audioEngine.start()
|
try self.audioEngine.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user