Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

1.8 KB
Raw Blame
import AVFAudio
import Speech
import UIKit

/// The two things Yogurt asks iOS for: the microphone to record, speech recognition to write the transcript.
enum Permission: CaseIterable {
    case microphone, speech

    /// restricted: Screen Time or a work or school profile decides; the person can't turn it on here
    enum Access { case on, off, notAsked, restricted }

    var access: Access {
        switch self {
        case .microphone:
            switch AVAudioApplication.shared.recordPermission {
            case .granted: .on
            case .denied: .off
            default: .notAsked
            }
        case .speech:
            switch SFSpeechRecognizer.authorizationStatus() {
            case .authorized: .on
            case .denied: .off
            case .restricted: .restricted
            default: .notAsked
            }
        }
    }

    var name: String { self == .microphone ? S.micTitle : S.speechTitle }
    var symbol: String { self == .microphone ? "mic" : "waveform" }

    /// Shows the system prompt. True when it was turned on.
    func request() async -> Bool {
        switch self {
        case .microphone: await AVAudioApplication.requestRecordPermission()
        case .speech: await Self.requestSpeech() == .authorized
        }
    }

    /// Not on the main actor: iOS calls back on a queue of its own.
    private nonisolated static func requestSpeech() async -> SFSpeechRecognizerAuthorizationStatus {
        await withCheckedContinuation { done in SFSpeechRecognizer.requestAuthorization { done.resume(returning: $0) } }
    }

    /// Once turned off, only the Settings app can turn it back on.
    @MainActor static func openSettings() {
        if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) }
    }
}