hex/ios/HEXMobile/SpeechEngineChoice.swift
Ryan Vogel 4f51dbbc1a
iOS: plainer interface wording (copy pass) (#2345)
* iOS: plainer interface wording (copy pass)

A TestFlight tester on build 121 said the interface reads as machine-written.
This rewrites 84 user-facing strings (80 catalog entries, the two permission
prompts, two keyboard-only errors) in flat, short, Apple-Settings style and
updates every changed zh-Hans value to match.

What changed:
- Notes that explained the mechanism, restated the row title, or reassured
  are cut to the one fact people need (e.g. Hide word suggestions now says
  "Autocorrect still works"; Learn how I type, Record typing logs, the
  Experiments rows, the Languages hint, onboarding notes, intents).
- Removed notes that said nothing: Auto-capitalization, Key pop-ups, and
  the iPad-only "The full keyboard works on iPad too" (its runsOnPad helper
  went with it). Haptics and the dictation bar now say "Needs Full Access"
  only while Full Access is off, instead of "Needs Full Access, which isn't
  on yet" / a note that repeated the requirement while it was on.
- One name per thing: "speech model" and "multilingual model" instead of
  Parakeet V2/Ultra in errors; "Apple's speech recognition" instead of
  Apple Speech / Apple's on-device speech; "No speech heard." for every
  empty recording; "Hex Keyboard" for iOS's name, "the Hex keyboard" in
  prose; US spelling (off-center, key centers).
- Permission prompts drop the sentence that restated "on this iPhone"
  (Info.plist, project.yml, zh-Hans InfoPlist.strings).
- Wording only: no settings keys, layout or behaviour changed. Catalog
  edits are confined to the changed entries; stale entries and the
  unlocalized UIKit strip strings are left as they were.

Verified: built before (8583160e) and after; screenshots of 21 scenes on
iPhone 17 Pro and iPhone SE (3rd gen) iOS 27.2 sims, EN before/after and
zh-Hans after, at default and AX5 text sizes, no truncation. xcodebuild test
on a fresh iPhone 17 Pro sim: TEST SUCCEEDED (DictationControllerTests
updated where they asserted the old wording; README quotes updated).

* iOS: Onboarding's doc comment quotes the new optimizing status

Matches the wording changed in the copy pass; comment only.

* iOS: keep the privacy facts in the copy pass; translate the keyboard strip

Review on #2345: for Hex, "on this iPhone", "never leaves" and "not sent"
are facts people need at that moment, not reassurance.

Restored:
- Microphone prompt: "...Audio never leaves it and is deleted once it's
  transcribed." Speech Recognition prompt keeps "Nothing you say is sent to
  a server." (Info.plist, project.yml, zh-Hans InfoPlist.strings)
- Learn how I type and Record typing logs say "on this iPhone" again.
- Clean up what I say is back to "Drops ums, repeats and corrected words".
- "Allow Speech Recognition. It stays on this iPhone." and "...in Settings.
  It runs on this iPhone." back to the originals.
- On-device put back in the shortest form: Checking on-device speech
  recognition; the Parakeet memory fallback names Apple's on-device speech
  recognition; Adaptive touch learns "on this iPhone"; the Shortcut, Control
  Center and Live Activity descriptions say "on device" / "on-device" (not
  "iPhone": KeyboardBridgeTests forbids Apple platform names in intent
  strings).

Keyboard strip: Undo dictation, Paste, Paste dictation, Code from Messages
(and its VoiceOver hint), Undoes the autocorrection, the Full Access hint
(title, Settings path, spoken path, Open Hex, its hint) and the dictation
bar's Full Access path were plain strings, so Chinese users saw English.
They now go through String(localized:); the keyboard extension already
bundles HEXMobile/Localizable.xcstrings, so no wiring was needed. 10 new
catalog entries with zh-Hans, using the app's terms (粘贴听写, 完全访问).

Verified: the built HEXKeyboard.appex zh-Hans Localizable.strings carries the
new keys; zh screenshots show 撤销听写 in the strip and the translated path
in the dictation bar; scripts/code-shape.py has no hard problems;
xcodebuild test on a fresh iPhone 17 Pro sim: TEST SUCCEEDED.
2026-11-22 03:45:00 -05:00

79 lines
3.8 KiB
Swift

import Foundation
/// The engines Hex dictates with.
nonisolated enum SpeechEngine: Equatable, Sendable {
/// Apple Speech (`SpeechAnalyzer`, iOS 26+): `SpeechTranscriber`, else `DictationTranscriber`.
case appleSpeech
/// FluidAudio Parakeet V2: English only, loaded into Hex.
case parakeet
/// Apple's `SFSpeechRecognizer` on the iPhone only (`OnDeviceSpeechTranscriber`), before
/// iOS 26. Its model runs in Apple's speech service, so it needs no room in Hex.
case onDeviceRecognizer
}
/// What picks the engine: the iPhone's iOS and memory, and how Parakeet's loads went.
///
/// From iOS 26, Apple Speech takes every language it has, and English stays on Parakeet only
/// where Apple has no `SpeechTranscriber` and Parakeet has room (`appleSpeechPicks`), as
/// before. Never the recognizer there, so iOS 26 never asks for Speech Recognition.
///
/// Before iOS 26 Parakeet dictates English where it has room; everything else goes to the
/// recognizer: every other language (Parakeet hears Chinese as English words), and English on
/// an iPhone with 3 GB (iPhone XR: iOS ends Hex while Parakeet loads, TestFlight build 56), after
/// a Parakeet load that ended with Hex (`ParakeetLoadGuard`), or while less memory is left
/// than loading Parakeet takes (`ParakeetTranscriber.loadMemory`).
nonisolated struct SpeechEngineChoice: Equatable, Sendable {
/// iOS's major version.
var system: Int
/// `ProcessInfo.physicalMemory`.
var physicalMemory: UInt64
/// `os_proc_available_memory()`: 0 where iOS sets no limit (the simulator).
var availableMemory: UInt64
/// A Parakeet load ended with Hex, or found too little memory (`ParakeetLoadGuard`).
var parakeetSetAside: Bool
/// 3 GB iPhones (iPhone XR, SE 2nd generation) report about 2.8 GB, 4 GB ones about 3.7 GB.
static let smallMemory: UInt64 = 3 << 30
static var current: SpeechEngineChoice {
SpeechEngineChoice(
system: ProcessInfo.processInfo.operatingSystemVersion.majorVersion,
physicalMemory: ProcessInfo.processInfo.physicalMemory,
availableMemory: UInt64(max(0, os_proc_available_memory())),
parakeetSetAside: ParakeetLoadGuard().lastLoadWasInterrupted
)
}
/// Whether Parakeet can load here now, before iOS 26.
var parakeetHasRoom: Bool {
physicalMemory > Self.smallMemory
&& !parakeetSetAside
&& ParakeetTranscriber.hasRoomToLoad(available: availableMemory)
}
/// From iOS 26, `AppleSpeechTranscriber.shouldUse`'s `parakeetFits`: 6 GB and up, as before,
/// and never after a load that ended Hex or with too little left.
var parakeetFitsBesideAppleSpeech: Bool {
physicalMemory >= 5 << 30
&& !parakeetSetAside
&& ParakeetTranscriber.hasRoomToLoad(available: availableMemory)
}
/// `language` is the dictation language (BCP 47), nil when unknown (English).
/// `appleSpeechPicks` is iOS 26's answer (`DictationController.appleSpeechLanguage`).
func engine(for language: String?, appleSpeechPicks: Bool) -> SpeechEngine {
if system >= 26 {
return appleSpeechPicks ? .appleSpeech : .parakeet
}
guard SpeechLanguagePicker.isEnglish(language), parakeetHasRoom else { return .onDeviceRecognizer }
return .parakeet
}
/// Why Hex moved English off Parakeet before iOS 26, when it did because of Parakeet
/// itself rather than the iPhone's size, for home's notice.
func notice(for language: String?) -> String? {
guard system < 26, SpeechLanguagePicker.isEnglish(language), physicalMemory > Self.smallMemory,
!parakeetHasRoom else { return nil }
return String(localized: "Not enough memory for the speech model. Hex is using Apple's on-device speech recognition.")
}
}