hex/ios/HEXShared/SpeechModelStore.swift
Ryan Vogel 5b137317c6 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 16:34:00 -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)
}
}