Files
voicediary/VoiceDiary/Services/SpeechAuthorization.swift
Felix Förtsch 3d42c83f75 fix speech authorization crash: decouple from SwiftData context
- 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>
2026-02-15 23:31:59 +01:00

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)
}
}
}
}