- Make TranscriptionService a plain Sendable class (not @Observable/@MainActor) - Request speech authorization in ContentView.onAppear via callback (no async) - Use @State pendingMemo + Task in View for transcription (Swift 6 safe) - Separate saveRecording() and startTranscription() to avoid data races Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
19 lines
443 B
Swift
19 lines
443 B
Swift
import Speech
|
|
|
|
enum SpeechAuthorization {
|
|
static func requestIfNeeded(completion: @MainActor @escaping @Sendable (Bool) -> Void) {
|
|
let status = SFSpeechRecognizer.authorizationStatus()
|
|
if status == .notDetermined {
|
|
SFSpeechRecognizer.requestAuthorization { newStatus in
|
|
Task { @MainActor in
|
|
completion(newStatus == .authorized)
|
|
}
|
|
}
|
|
} else {
|
|
Task { @MainActor in
|
|
completion(status == .authorized)
|
|
}
|
|
}
|
|
}
|
|
}
|