mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
* 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.
149 lines
6.4 KiB
Swift
149 lines
6.4 KiB
Swift
import FluidAudio
|
||
import Foundation
|
||
import os
|
||
|
||
/// Experiments › Multilingual model (Parakeet): Parakeet Ultra (`ParakeetUltraModel`) through
|
||
/// FluidAudio's v3 decoder, in Hex's own process. It hears its 25 languages without being told
|
||
/// which, mixed within a sentence, so `languageIdentifier` only names the dictation language
|
||
/// for the steps after it (formatting, lists, cleanup).
|
||
actor ParakeetUltraTranscriber: LocalTranscribing {
|
||
enum TranscriberError: HexDescribedError {
|
||
case notPrepared
|
||
case emptyTranscript
|
||
case notEnoughMemory
|
||
/// Not on the iPhone yet: `ParakeetUltraDownload` gets it beside the usual engine.
|
||
case notDownloaded
|
||
|
||
var errorDescription: String? {
|
||
switch self {
|
||
case .notPrepared:
|
||
String(localized: "The multilingual model isn't ready.")
|
||
case .emptyTranscript:
|
||
String(localized: "No speech heard.")
|
||
case .notEnoughMemory:
|
||
String(localized: "Not enough memory for the multilingual model.")
|
||
case .notDownloaded:
|
||
String(localized: "The multilingual model isn't downloaded yet.")
|
||
}
|
||
}
|
||
}
|
||
|
||
static let name = "Parakeet Ultra"
|
||
/// After a load that ended Hex (`ParakeetLoadGuard`), beside Try again.
|
||
nonisolated static var setAsideMessage: String {
|
||
String(localized: "Hex closed while getting the multilingual model ready, likely short of memory.")
|
||
}
|
||
/// `ParakeetLoadGuard`'s and `ParakeetCompileRecord`'s keys, apart from V2's.
|
||
static let loadGuardModel = "parakeetUltra"
|
||
static let compileRecordKey = "parakeetUltra.compiledForSystem"
|
||
|
||
/// What loading it takes in Hex, as `ParakeetTranscriber.loadMemory` for V2: the encoder
|
||
/// is 594 MB of int8 weights, which the Neural Engine may hold as 16-bit (1.2 GB) before
|
||
/// the A17, then the other three models (a joint four times V2's) and a first transcription.
|
||
nonisolated static let loadMemory: UInt64 = 1_500 << 20
|
||
|
||
/// Whether `available` (`os_proc_available_memory`) leaves room to load it. 0 means iOS
|
||
/// didn't say (the simulator).
|
||
nonisolated static func hasRoomToLoad(available: UInt64) -> Bool {
|
||
available == 0 || available >= loadMemory
|
||
}
|
||
|
||
nonisolated let displayName = ParakeetUltraTranscriber.name
|
||
let languageIdentifier: String
|
||
private var manager: AsrManager?
|
||
|
||
init(language: String) {
|
||
languageIdentifier = language
|
||
}
|
||
|
||
var languageName: String {
|
||
SpeechLanguagePicker.displayName(for: languageIdentifier)
|
||
}
|
||
|
||
/// The language the experiment dictates in now, or nil for the engine Hex uses without it:
|
||
/// off, an iPhone without the memory, a language it doesn't know, a load that ended Hex
|
||
/// (`ParakeetLoadGuard`, until the experiment is turned off and on), or less memory left
|
||
/// than loading takes (`os_proc_available_memory`, 0 where iOS sets no limit).
|
||
nonisolated static func chosenLanguage(
|
||
language: String? = MultilingualParakeetSettings().language(),
|
||
availableMemory: UInt64 = UInt64(max(0, os_proc_available_memory())),
|
||
setAside: Bool = ParakeetLoadGuard(model: loadGuardModel).lastLoadWasInterrupted
|
||
) -> String? {
|
||
guard let language, !setAside, hasRoomToLoad(available: availableMemory) else { return nil }
|
||
return language
|
||
}
|
||
|
||
/// "632.2 MB", kept on one line.
|
||
nonisolated static var downloadSize: String {
|
||
ByteCountFormatter.string(fromByteCount: ParakeetUltraModel.totalBytes, countStyle: .file)
|
||
.replacingOccurrences(of: " ", with: "\u{00A0}")
|
||
}
|
||
|
||
/// Whether Core ML compiled it for this iOS already, so loading it takes seconds rather
|
||
/// than the minute or more of a first load.
|
||
nonisolated static var isCompiled: Bool {
|
||
ParakeetCompileRecord(key: compileRecordKey).isCurrent
|
||
}
|
||
|
||
/// Loads the downloaded model; the download itself is `ParakeetUltraDownload`'s, beside
|
||
/// the engine Hex dictates with meanwhile.
|
||
func prepare(
|
||
progressHandler: @escaping @Sendable (ModelPreparationProgress) -> Void
|
||
) async throws {
|
||
guard manager == nil else { return }
|
||
guard ParakeetUltraModel.isDownloaded() else { throw TranscriberError.notDownloaded }
|
||
|
||
let compiled = ParakeetCompileRecord(key: Self.compileRecordKey)
|
||
let progress = ParakeetProgressFeed(
|
||
ParakeetPreparationProgress(downloads: false, compiledBefore: compiled.isCurrent),
|
||
emit: progressHandler
|
||
)
|
||
let ticker = Task {
|
||
while !Task.isCancelled {
|
||
progress.tick()
|
||
try? await Task.sleep(for: .milliseconds(250))
|
||
}
|
||
}
|
||
defer { ticker.cancel() }
|
||
|
||
// As V2: only the load, where iOS can end Hex short of memory, counts for the guard,
|
||
// and too little left to load it sets it aside for the engine Hex uses without it.
|
||
let loads = ParakeetLoadGuard(model: Self.loadGuardModel)
|
||
guard Self.hasRoomToLoad(available: UInt64(max(0, os_proc_available_memory()))) else {
|
||
loads.setAside()
|
||
throw TranscriberError.notEnoughMemory
|
||
}
|
||
loads.begin()
|
||
var loaded = false
|
||
defer { loads.end(loaded: loaded) }
|
||
progress.update { $0.startLoading(at: Date.now.timeIntervalSinceReferenceDate) }
|
||
let models = try ParakeetUltraModel.load {
|
||
let now = Date.now.timeIntervalSinceReferenceDate
|
||
progress.update { $0.finishModel(at: now) }
|
||
}
|
||
let manager = AsrManager(config: .default)
|
||
try await manager.loadModels(models)
|
||
self.manager = manager
|
||
loaded = true
|
||
compiled.markCurrent()
|
||
progress.update { $0.finish() }
|
||
}
|
||
|
||
func transcribe(_ audioURL: URL) async throws -> String {
|
||
guard let manager else {
|
||
throw TranscriberError.notPrepared
|
||
}
|
||
let decoderLayers = await manager.decoderLayerCount
|
||
var decoderState = TdtDecoderState.make(decoderLayers: decoderLayers)
|
||
let result = try await manager.transcribe(audioURL, decoderState: &decoderState)
|
||
let text = result.text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||
guard !text.isEmpty else {
|
||
throw TranscriberError.emptyTranscript
|
||
}
|
||
return text
|
||
}
|
||
}
|
||
|
||
extension ParakeetUltraTranscriber.TranscriberError: NoSpeechError {
|
||
var meansNoSpeech: Bool { self == .emptyTranscript }
|
||
}
|