mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS: both speech models download on Wi-Fi, with Use mobile data What: Settings › Dictation › Model's two downloads now follow one rule (SpeechModelDownloadNetwork). On Wi-Fi (KeyboardParakeetDownload.isUnmetered: not cellular, a hotspot or Low Data Mode) a picked model downloads as before. Off Wi-Fi it waits: English's line already said "Downloads on Wi-Fi."; Multilingual's now says the same (ParakeetUltraDownload.State.waitingForWiFi) instead of starting at once. Both lines get a Use mobile data action that starts that download now. Wi-Fi coming back starts a waiting download by itself; a multilingual download running on Wi-Fi now stops where it is when Wi-Fi goes (its files resume), as English's always did. Use mobile data is one decision for that model's download, kept in the App Group until the model is on the iPhone (a stop, Try again or relaunch carries on); picking the other model forgets it. Multilingual's row text now reads "A 632.2 MB download on Wi-Fi." (zh-Hans updated); the one new string is "Use mobile data" (zh-Hans 使用蜂窝数据). English's own network monitor moved into SpeechModelDownloadNetwork, which both downloads observe. Unchanged: a download already running on Wi-Fi; unpicked (the old model stays until the new one is downloaded and has loaded once); picking English still stops and removes a partial multilingual download; the keyboard extension and its notice; the Speech model in keyboard switch turned on by hand still downloads English on any connection. Why: TestFlight build 151 (no Wi-Fi at home): English waited for Wi-Fi but Multilingual started a 632 MB download over mobile data the moment it was picked. Ryan's decision: wait for Wi-Fi, with a Use mobile data button, as on Android. Verified: tests in DictationControllerTests (both wait off Wi-Fi, Use mobile data starts them, Wi-Fi returning starts a waiting one, leaving Wi-Fi stops one, both start at once on Wi-Fi, picking the other model asks again); suite run separately. * iOS: test that English picked mid-wait leaves a waiting multilingual download stopped What: the multilingual Wi-Fi test now also stops a download waiting for Wi-Fi (what picking English does) and checks Wi-Fi coming back doesn't start it, and that picking Multilingual again waits again. Why: the task asks for switching models mid-wait to be covered. Verified: suite run separately. * iOS: snapshot scenes for Settings › Dictation › Model's download states What: --snap-state settings-dictation-model-<english|multilingual>-<waiting|downloading|ready> opens Settings › Dictation with that model picked and its download in that state (DictationController.applySpeechModelFixture, ParakeetUltraDownload.applyFixture(share:)). Waiting goes through the real rule: with --simulate-cellular the connection reads as off Wi-Fi and the keyboard limit is recorded, so only the connection holds the download. SettingsSnapshotFixture.applyDefaults keeps Multilingual picked for -multilingual- scenes. Why: screenshots of the Use mobile data row in each state; the simulator has no cellular. Verified: scenes rendered in a simbox (screenshots in the PR). * iOS: Model snapshot scenes record the keyboard limit only for waiting What: settings-dictation-model-*-downloading and -ready no longer record a keyboard limit. Why: with a limit and the simulator's Wi-Fi, English's real download started under the downloading scene and finished during the screenshot run, so a later downloading shot read Downloaded. Without a limit nothing downloads, as with Home's model-card scenes. Verified: the 12 Model row screenshots retaken in the simbox. * iOS: check the multilingual Wi-Fi test's resume request, not the last request What: testAMultilingualDownloadFollowsWiFiComingAndGoing now checks the first two requests are the fresh one and the bytes=800- resume, instead of the last request. Why: the stub model has two files, so the last request is the second file's, with no range; the suite failed on that assertion alone. Verified: full suite rerun in the simbox.
358 lines
14 KiB
Swift
358 lines
14 KiB
Swift
import SwiftUI
|
||
|
||
/// Single choice for live dictation feedback on iOS 26+: off, preview in the keyboard bar,
|
||
/// or typing live into the text field. Backed by `LiveDictationSettings`'s existing keys so
|
||
/// existing preferences migrate without data loss.
|
||
enum LiveDictationMode: String, CaseIterable {
|
||
case off
|
||
case preview
|
||
case typeIntoField
|
||
|
||
var label: String {
|
||
switch self {
|
||
case .off: String(localized: "Off")
|
||
case .preview: String(localized: "In bar")
|
||
case .typeIntoField: String(localized: "Into field")
|
||
}
|
||
}
|
||
|
||
var detail: String? {
|
||
switch self {
|
||
case .off, .preview: nil
|
||
case .typeIntoField: String(localized: "Words can change until you stop")
|
||
}
|
||
}
|
||
|
||
static func read(from settings: LiveDictationSettings = LiveDictationSettings()) -> LiveDictationMode {
|
||
if settings.typesIntoField { return .typeIntoField }
|
||
if settings.showsPreview { return .preview }
|
||
return .off
|
||
}
|
||
|
||
func write(to settings: LiveDictationSettings = LiveDictationSettings()) {
|
||
switch self {
|
||
case .off:
|
||
settings.showsPreview = false
|
||
settings.typesIntoField = false
|
||
case .preview:
|
||
settings.showsPreview = true
|
||
settings.typesIntoField = false
|
||
case .typeIntoField:
|
||
settings.showsPreview = false
|
||
settings.typesIntoField = true
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Settings › Dictation: Style and Language first, then Formatting (hiding controls Verbatim
|
||
/// ignores), live words, cleanup/vocabulary, and the speech model + microphone.
|
||
struct DictationSettingsPage: View {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@Bindable var dictation: DictationController
|
||
/// From Home's speech model card: the page starts at Speech model in keyboard.
|
||
var opensAtSpeechModel = false
|
||
static let speechModelRow = "speech-model-in-keyboard"
|
||
@State private var revision = 0
|
||
@State private var keyboardParakeet = KeyboardParakeetSettings().isOn
|
||
private let keyboardParakeetFits = KeyboardParakeetSettings.fits()
|
||
/// English or Multilingual (`SpeechModelChoice`), on iPhones with the memory for either.
|
||
@State private var speechModel = SpeechModelChoice.current
|
||
/// Keep mic warm stays on the page once picked, even Off where it would hide.
|
||
@State private var keepsWarmRow = false
|
||
|
||
private var showsStyleFormatting: Bool {
|
||
dictation.style != .verbatim
|
||
}
|
||
|
||
private func toggleBinding(_ get: @escaping () -> Bool, _ set: @escaping (Bool) -> Void) -> Binding<Bool> {
|
||
Binding(
|
||
get: {
|
||
_ = revision
|
||
return get()
|
||
},
|
||
set: { value in
|
||
set(value)
|
||
revision += 1
|
||
}
|
||
)
|
||
}
|
||
|
||
private var liveMode: LiveDictationMode {
|
||
_ = revision
|
||
return LiveDictationMode.read()
|
||
}
|
||
|
||
private var customVocabularyOn: Bool {
|
||
_ = revision
|
||
return CustomVocabularySettings().isEnabled
|
||
}
|
||
|
||
var body: some View {
|
||
SettingsPageScaffold(title: "Dictation", startsAt: opensAtSpeechModel ? Self.speechModelRow : nil) {
|
||
SettingsCard {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Style"))
|
||
Spacer(minLength: 8)
|
||
Menu {
|
||
ForEach(DictationStyle.allCases, id: \.self) { candidate in
|
||
Button {
|
||
dictation.setStyle(candidate)
|
||
} label: {
|
||
if dictation.style == candidate {
|
||
Label(candidate.label, systemImage: "checkmark")
|
||
} else {
|
||
Text(candidate.label)
|
||
}
|
||
}
|
||
}
|
||
} label: {
|
||
SettingsMenuValue(value: dictation.style.label)
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 48)
|
||
|
||
DictationLanguageRow(dictation: dictation)
|
||
|
||
SettingsDivider()
|
||
|
||
TranslateDictationRow()
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
}
|
||
|
||
SettingsSectionHeader(title: "Formatting")
|
||
|
||
SettingsCard {
|
||
// After the style, on every path (`DictationPipeline`). Casual lowercases sentence
|
||
// starts by itself, which read as this switch not working (TestFlight build 149).
|
||
SettingsToggleRow(
|
||
title: String(localized: "Lowercase"),
|
||
detail: dictation.style == .casual
|
||
? String(localized: "Casual starts sentences lowercase anyway. Pick Polished for capitals.")
|
||
: nil,
|
||
isOn: toggleBinding(
|
||
{ DictationLowercaseSettings().isEnabled },
|
||
{ DictationLowercaseSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
// Inside the style, on every path (`SpokenLists`).
|
||
SettingsToggleRow(
|
||
title: String(localized: "Format lists"),
|
||
detail: String(localized: "Say “first, second” or “bullet” for a list"),
|
||
isOn: toggleBinding(
|
||
{ DictationListSettings().isEnabled },
|
||
{ DictationListSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
// Spoken punctuation, Numbers as digits, and End with a period are ignored in
|
||
// Verbatim, so hide them when Verbatim is active.
|
||
if showsStyleFormatting {
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Spoken punctuation"),
|
||
detail: String(localized: "Say “comma” or “question mark”"),
|
||
isOn: toggleBinding(
|
||
{ DictationPunctuationSettings().isEnabled },
|
||
{ DictationPunctuationSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Numbers as digits"),
|
||
detail: String(localized: "“Five point five” becomes 5.5"),
|
||
isOn: toggleBinding(
|
||
{ DictationNumberSettings().isEnabled },
|
||
{ DictationNumberSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "End with a period"),
|
||
detail: String(localized: "Off still keeps ? and !"),
|
||
isOn: toggleBinding(
|
||
{ DictationPeriodSettings().isEnabled },
|
||
{ DictationPeriodSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
}
|
||
}
|
||
|
||
// While the keyboard records by itself (iOS 26 and later): one 3-way choice for live
|
||
// words instead of two interacting switches.
|
||
if #available(iOS 26.0, *) {
|
||
SettingsCard {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(
|
||
title: String(localized: "Live words"),
|
||
detail: liveMode.detail
|
||
)
|
||
Spacer(minLength: 8)
|
||
SettingsSegments(
|
||
items: LiveDictationMode.allCases,
|
||
selected: liveMode,
|
||
label: \.label,
|
||
onSelect: { mode in
|
||
mode.write()
|
||
revision += 1
|
||
}
|
||
)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
}
|
||
}
|
||
|
||
SettingsCard {
|
||
SettingsToggleRow(
|
||
title: String(localized: "Clean up what I say"),
|
||
detail: String(localized: "Drops ums, repeats and corrected words"),
|
||
isOn: toggleBinding(
|
||
{ CleanupTaggerSettings().isEnabled },
|
||
{ CleanupTaggerSettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Custom vocabulary"),
|
||
detail: String(localized: "Spell names and terms your way"),
|
||
isOn: toggleBinding(
|
||
{ CustomVocabularySettings().isEnabled },
|
||
{ CustomVocabularySettings().isEnabled = $0 }
|
||
)
|
||
)
|
||
|
||
if customVocabularyOn {
|
||
CustomVocabularyEditor()
|
||
.padding(.horizontal, 16)
|
||
.padding(.top, 2)
|
||
.padding(.bottom, 14)
|
||
}
|
||
|
||
HexWordsRows(isOn: customVocabularyOn)
|
||
}
|
||
|
||
SettingsCard {
|
||
SettingsToggleRow(
|
||
title: String(localized: "Speech model in keyboard"),
|
||
detail: keyboardParakeetFits
|
||
? String(localized: "The keyboard dictates with the model below. Until it's ready, it uses Apple's speech recognition.")
|
||
: String(localized: "Needs an iPhone with 6 GB of memory or more"),
|
||
isOn: $keyboardParakeet
|
||
)
|
||
.disabled(!keyboardParakeetFits)
|
||
|
||
// Where the iPhone has the memory for either model (the switch above says why not).
|
||
if keyboardParakeetFits {
|
||
SettingsDivider()
|
||
|
||
SpeechModelChoiceRow(choice: speechModel) { choice in
|
||
choice.select()
|
||
withAnimation(HexMotion.settleAnimation(reduceMotion: reduceMotion)) {
|
||
speechModel = SpeechModelChoice.current
|
||
}
|
||
}
|
||
|
||
if speechModel == .multilingual {
|
||
MultilingualModelStatus(
|
||
download: dictation.multilingualDownload,
|
||
retry: { dictation.retryMultilingualParakeet() },
|
||
turnOff: { SpeechModelChoice.english.select(); speechModel = .english },
|
||
useMobileData: { dictation.useMobileDataForMultilingualParakeet() }
|
||
)
|
||
.padding(.horizontal, 12)
|
||
.padding(.bottom, 12)
|
||
}
|
||
}
|
||
|
||
if keyboardParakeet {
|
||
KeyboardParakeetStatus(
|
||
download: KeyboardParakeetDownload.shared,
|
||
multilingual: speechModel == .multilingual,
|
||
offersMobileData: true
|
||
)
|
||
.padding(.horizontal, 12)
|
||
.padding(.bottom, 12)
|
||
}
|
||
|
||
// Hidden where the keyboard dictates by itself and it would say Off.
|
||
if keepsWarmRow || dictation.showsKeepMicWarm {
|
||
SettingsDivider()
|
||
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Keep mic warm"))
|
||
Spacer(minLength: 8)
|
||
SettingsSegments(
|
||
items: WarmSessionDuration.allCases,
|
||
selected: dictation.warmDuration,
|
||
label: \.shortLabel,
|
||
onSelect: { duration in
|
||
keepsWarmRow = true
|
||
withAnimation(HexMotion.settleAnimation(reduceMotion: reduceMotion)) {
|
||
dictation.selectWarmDuration(duration)
|
||
}
|
||
}
|
||
)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 50)
|
||
}
|
||
|
||
SettingsDivider()
|
||
|
||
// With a car, headset or headphones connected (`MicrophoneRoute`).
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(
|
||
title: String(localized: "Microphone"),
|
||
detail: dictation.microphone.detail
|
||
)
|
||
Spacer(minLength: 8)
|
||
Menu {
|
||
ForEach(MicrophoneChoice.allCases, id: \.self) { candidate in
|
||
Button {
|
||
dictation.setMicrophone(candidate)
|
||
} label: {
|
||
if dictation.microphone == candidate {
|
||
Label(candidate.label, systemImage: "checkmark")
|
||
} else {
|
||
Text(candidate.label)
|
||
}
|
||
}
|
||
}
|
||
} label: {
|
||
SettingsMenuValue(value: dictation.microphone.label)
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
}
|
||
.id(Self.speechModelRow)
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: customVocabularyOn)
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: showsStyleFormatting)
|
||
.onChange(of: keyboardParakeet) { _, enabled in
|
||
guard enabled != KeyboardParakeetSettings().isEnabled else { return }
|
||
KeyboardParakeetSettings().isEnabled = enabled
|
||
DictationController.shared.keyboardParakeetChanged()
|
||
}
|
||
.onAppear {
|
||
keyboardParakeet = KeyboardParakeetSettings().isOn
|
||
speechModel = SpeechModelChoice.current
|
||
revision += 1
|
||
}
|
||
}
|
||
}
|