hex/ios/HEXShared/DictationEngine.swift
Ryan Vogel d29b13e7eb iOS: Hex gets the keyboard's Apple model ready when it dictates with the multilingual model
With Hex's engine on the multilingual model, KeyboardSpeechPreparation
took the keyboard's speech as following Hex (keyboardSpeechFollowsApp was
true for Parakeet Ultra) because the keyboard used to send those
dictations to Hex. Since the previous commit the keyboard dictates them
itself, with Apple's speech recognition until it has the multilingual
model loaded, so Hex now gets that language's Apple model ready for the
keyboard as it does with Parakeet V2. Without this, the keyboard would
have had to download it on its first dictation.

Verified: DictationSSOTTests' engine case updated to expect it; the full
suite runs on the Studio.
2026-11-24 09:29:45 -05:00

49 lines
1.8 KiB
Swift

import Foundation
/// The speech engine Hex dictates with. Display copy lives in `displayName`; every decision
/// switches on the enum instead of comparing display strings.
nonisolated enum DictationEngine: Equatable, Sendable {
/// Launch hasn't resolved the engine yet.
case undecided
/// iOS 26+ `SpeechAnalyzer` (`SpeechTranscriber` or `DictationTranscriber`).
case appleSpeech
/// Pre-iOS 26 on-device `SFSpeechRecognizer` (model managed by iOS, never downloaded by Hex).
case onDeviceRecognizer
/// FluidAudio Parakeet V2 (English).
case parakeetV2
/// FluidAudio Parakeet Ultra (multilingual).
case parakeetUltra
var displayName: String {
switch self {
case .undecided: "Local speech"
case .appleSpeech, .onDeviceRecognizer: "Apple Speech"
case .parakeetV2: "Parakeet V2"
case .parakeetUltra: "Parakeet Ultra"
}
}
var isAppleSpeech: Bool {
self == .appleSpeech || self == .onDeviceRecognizer
}
/// Whether getting this engine ready downloads a model in Hex (not `SFSpeechRecognizer`,
/// whose model iOS keeps).
var downloads: Bool {
self != .onDeviceRecognizer
}
/// Whether the keyboard's own speech preparation simply follows Hex's app engine: Apple
/// Speech shares the same on-device model unless the keyboard can't get it
/// (`keyboardNeedsHex`). With Parakeet in Hex the keyboard still needs Apple's model, which
/// it dictates with until it has Parakeet loaded itself (the multilingual model's languages
/// too: they never go to Hex).
func keyboardSpeechFollowsApp(keyboardNeedsHex: Bool) -> Bool {
switch self {
case .appleSpeech, .onDeviceRecognizer:
!keyboardNeedsHex
case .undecided, .parakeetV2, .parakeetUltra:
false
}
}
}