mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
What: Settings › Dictation's speech model card was 11 lines of grey text on the largest iPhone and 13 on the smallest, with "Apple's speech recognition" three times: - switch subtitle: "Until it's ready, the keyboard uses Apple's speech recognition" (准备好之前,键盘使用 Apple 的语音识别), was "The keyboard dictates with the model below. Until it's ready, it uses Apple's speech recognition."; - English: "A 464.4 MB download on Wi-Fi" (通过 Wi-Fi 下载 %@), was "For English. A …"; - Multilingual: "25 European languages, even mixed in one sentence. A 632.2 MB download on Wi-Fi." (支持 25 种欧洲语言,一句话里混着说也行。通过 Wi-Fi 下载 %@。); the 25 names and "Hex dictates them with it too." leave the page. All 25 are European languages (MultilingualParakeetSettings.languages), so "European" holds; - paragraph: "Other languages use Apple's speech recognition. Switching models downloads the new one and removes the old." (其他语言使用 Apple 的语音识别。切换模型会下载新模型并删除旧模型。). Removed: SpeechModelChoice.multilingualLanguages, which only built the 25 names. Why: quality review for 1.0.5 (both reviewers), section B. Verified: DictationSSOTTests checks the 25 languages are the European set; screenshots in a simbox; suite separately.
103 lines
4.4 KiB
Swift
103 lines
4.4 KiB
Swift
import SwiftUI
|
||
|
||
/// Settings › Dictation › Model: the speech model the keyboard dictates with, English or
|
||
/// Multilingual. Multilingual is `MultilingualParakeetSettings` (the setting Experiments had),
|
||
/// so Hex's own dictation follows it too. English unless picked.
|
||
enum SpeechModelChoice: String, CaseIterable, Hashable {
|
||
case english
|
||
case multilingual
|
||
|
||
static var current: SpeechModelChoice {
|
||
MultilingualParakeetSettings().isEnabled ? .multilingual : .english
|
||
}
|
||
|
||
var label: String {
|
||
switch self {
|
||
case .english: String(localized: "English")
|
||
case .multilingual: String(localized: "Multilingual")
|
||
}
|
||
}
|
||
|
||
/// What the choice means, before anything downloads: its download, and Multilingual's
|
||
/// languages (all 25 of `MultilingualParakeetSettings.languages` are European).
|
||
@MainActor
|
||
var detail: String {
|
||
switch self {
|
||
case .english:
|
||
String(localized: "A \(KeyboardParakeetDownload.format(KeyboardParakeetDownload.bytes)) download on Wi-Fi")
|
||
case .multilingual:
|
||
String(localized: "25 European languages, even mixed in one sentence. A \(ParakeetUltraTranscriber.downloadSize) download on Wi-Fi.")
|
||
}
|
||
}
|
||
|
||
/// Picked in Settings: Multilingual downloads beside the engine Hex dictates with, on Wi-Fi
|
||
/// or after Use mobile data; English stops that download (deleted unless complete) and gets
|
||
/// English's model as Speech model in keyboard does. The model picked before stays, and keeps
|
||
/// dictating English, until the new one is downloaded and has loaded once (`unpicked`).
|
||
/// Use mobile data was for the other model's download: this one asks again.
|
||
@MainActor
|
||
func select() {
|
||
guard self != Self.current else { return }
|
||
SpeechModelDownloadNetwork.shared.forgetMobileData()
|
||
MultilingualParakeetSettings().isEnabled = self == .multilingual
|
||
DictationController.shared.multilingualParakeetChanged()
|
||
DictationController.shared.startKeyboardParakeetDownloadIfWanted()
|
||
}
|
||
}
|
||
|
||
extension SpeechModelChoice {
|
||
/// The model to remove now, if any: Settings › Dictation › Model keeps only the picked one,
|
||
/// but the other goes only once the picked one is downloaded and has loaded once (in Hex
|
||
/// or the keyboard), so nobody is left with neither; a download that fails or stops leaves
|
||
/// the other in place and in use. Never one Hex itself dictates with now.
|
||
static func unpicked(
|
||
picked: SpeechModelChoice,
|
||
englishDownloaded: Bool,
|
||
englishLoaded: Bool,
|
||
multilingualDownloaded: Bool,
|
||
multilingualLoaded: Bool,
|
||
hexDictatesWith: KeyboardParakeetPlan.Model?
|
||
) -> KeyboardParakeetPlan.Model? {
|
||
switch picked {
|
||
case .multilingual:
|
||
guard englishDownloaded, multilingualDownloaded, multilingualLoaded, hexDictatesWith != .parakeetV2 else { return nil }
|
||
return .parakeetV2
|
||
case .english:
|
||
guard multilingualDownloaded, englishDownloaded, englishLoaded, hexDictatesWith != .parakeetUltra else { return nil }
|
||
return .parakeetUltra
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The Model row in the speech model card: English · Multilingual, what the picked one means,
|
||
/// and that a downloaded model stays.
|
||
struct SpeechModelChoiceRow: View {
|
||
let choice: SpeechModelChoice
|
||
let onSelect: (SpeechModelChoice) -> Void
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Model"))
|
||
Spacer(minLength: 8)
|
||
SettingsSegments(
|
||
items: SpeechModelChoice.allCases,
|
||
selected: choice,
|
||
label: \.label,
|
||
onSelect: onSelect
|
||
)
|
||
}
|
||
Text(choice.detail)
|
||
.font(.system(size: 13))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
.accessibilityIdentifier("speech-model-choice-detail")
|
||
Text("Other languages use Apple's speech recognition. Switching models downloads the new one and removes the old.")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textFaint)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 12)
|
||
}
|
||
}
|