hex/ios/HEXShared/SpeechModelStore.swift
Ryan Vogel 843122d24e
iOS: Home card for Hex's own speech model, and Speech model in keyboard moves to Settings › Dictation (#2437)
* iOS: Home shows a card about Hex's own speech model and where its download stands

What changed
- SpeechModelHomeCard on Home, above the Paste card and in its style: "New: Hex's own speech
  model", "English dictation, right in the keyboard.", then KeyboardParakeetStatus (the
  same waiting, downloading, downloaded, getting ready and ready lines as Settings ›
  Experiments). Shown only while the switch is on, the iPhone fits and no hold says the
  keyboard never will use it (another engine, not English, a keyboard too small). Once ready
  it can be dismissed; the dismissal is kept in the App Group and the card never returns.
- --snap-state model-card-waiting|downloading|ready fixtures for simulator screenshots.
- Two new strings, with Simplified Chinese; every status line is an existing one.

Why
- Ryan asked whether 1.0.3 tells people to try the new model: the only mention was the switch
  under Settings › Experiments.

Verified
- DictationControllerTests: shown while waiting (each hold that clears), downloading or ready;
  not with the switch off, under 6 GB, not English, another engine or a keyboard too small;
  dismissed stays dismissed. Studio suite and screenshots are in the pull request.

* iOS: Speech model in keyboard moves from Settings › Experiments to Settings › Dictation

What changed
- The switch, its detail line and its status line (KeyboardParakeetStatus) leave the
  Experiments page and sit on the Dictation page in a card of their own, directly above the
  keyboard's live-words card (Show what I say, Type as I speak), below the card with Numbers
  as digits. Its own card because its status line sits under it, and it shows on every iOS
  while the live-words card is iOS 26 only.
- Home's card is now a tap target that opens Settings › Dictation (a chevron until it's ready,
  then the dismiss button), and its status line is drawn without a second box inside it.
- Comments and README that sent a reader to Experiments › Speech model in keyboard now name
  Settings › Dictation; README calls it "the switch", not "the experiment".
- Removed from ExperimentsSettingsPage: the row, its state and its onChange, moved unchanged
  into DictationSettingsPage.

Why
- Ryan: "Move it out of Experiments, please. Put it in Settings, Dictation."

Not changed
- The setting: same App Group key (experiments.keyboardParakeet), same default (on for English
  where the keyboard can use it), same turned-on-by-hand meaning, same download rules; a
  switch turned off stays off.

Verified
- Studio suite on the rebased head and simulator screenshots of both pages are in the pull
  request.
2026-11-22 18:03:28 -05:00

50 lines
2.6 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
/// Where Hex keeps Parakeet's Core ML files: in the App Group, so the keyboard can load them too
/// (Settings › Dictation › Speech model in keyboard). Before, they were in the app's own Application
/// Support, which the keyboard can't read; the app moves them here (`moveLegacyDownloads`),
/// never downloading them again. Each folder is marked complete once every file is on disk,
/// and the keyboard loads only a marked folder.
nonisolated enum SpeechModelStore {
/// FluidAudio's `Repo.parakeetV2.folderName`: its loader finds the files by this name.
static let parakeetV2Folder = "parakeet-tdt-0.6b-v2"
/// `ParakeetUltraModel`'s folder, named for its pinned revision.
static let parakeetUltraFolder = "parakeet-ultra-coreml-95eaa59"
static let completeMarker = ".hex-complete"
/// `Library/Application Support/SpeechModels` in the App Group (where devicectl can list it
/// too, which a group container's root isn't); the process's own Application Support where
/// there is no App Group (an unsigned simulator build).
static var root: URL {
let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: KeyboardBridge.appGroup)?
.appendingPathComponent("Library/Application Support", isDirectory: true)
?? FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
return base.appendingPathComponent("SpeechModels", isDirectory: true)
}
static var parakeetV2: URL { root.appendingPathComponent(parakeetV2Folder, isDirectory: true) }
static var parakeetUltra: URL { root.appendingPathComponent(parakeetUltraFolder, isDirectory: true) }
/// Every file of the model in `directory` is on disk.
static func isComplete(_ directory: URL) -> Bool {
FileManager.default.fileExists(atPath: directory.appendingPathComponent(completeMarker).path)
}
static func markComplete(_ directory: URL) {
guard FileManager.default.fileExists(atPath: directory.path) else { return }
FileManager.default.createFile(atPath: directory.appendingPathComponent(completeMarker).path, contents: Data())
}
static func clearComplete(_ directory: URL) {
try? FileManager.default.removeItem(at: directory.appendingPathComponent(completeMarker))
}
/// Creates `root`, out of backups (the models download again).
static func prepareRoot() {
var folder = root
try? FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
var values = URLResourceValues()
values.isExcludedFromBackup = true
try? folder.setResourceValues(values)
}
}