hex/ios/HEXShared/SpeechModelStore.swift
Ryan Vogel 4e7ef4720f iOS: Speech model in keyboard moves to Settings › Dictation; the keyboard logs resident and compressed memory
What changed
- The row (switch, detail and status) leaves Experiments for its own card in Settings ›
  Dictation (iOS 26 and later, where the keyboard can use it): it is the default engine for the
  keyboard's English dictation now, not an experiment. KeyboardParakeetRow (in
  KeyboardParakeetDownload.swift) owns the switch's state, the change handler and the status
  view that ExperimentsSettingsPage held; wording and behaviour unchanged.
- KeyboardProbeLog.memory() adds the keyboard's resident (task_vm_info internal) and compressed
  memory to every memory line, the recording's start and stop included, so the next long run
  can tell what the one-time step of about 15 MB at the ninth dictation is.
- Comments and README say Settings › Dictation.

Why
- Recommended once the switch became a default (#2390); the step needs these two numbers.

Verified
- Studio suite in the pull request.
2026-11-22 15:22:54 -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)
}
}