mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS: Hinglish romaniser, Hindi in Latin letters as people text it
Adds HinglishRomanizer and HinglishLexicon in HEXShared, so the app and
the keyboard share them, for the Hinglish experiment in the next commit.
Why: testers asked for Hindi dictation in the Latin alphabet ("kya kar
rahe ho"), not Devanagari and not translated. On macOS 27.2, Apple's
SpeechTranscriber hi-IN already writes Hindi in Latin letters, but
DictationTranscriber hi-IN (the module on iPhones without
SpeechTranscriber, and the fallback when its model won't install)
writes Devanagari, English words included (मीटिंग).
How:
- Devanagari words take the lexicon's spelling when it has them (about
45 common Hindi words, 270 English loanwords back in English).
Otherwise: Hindi schwa deletion, then ICU Devanagari-Latin, then casual
spelling (no diacritics; aa/ee/oo only where stressed; ch, sh, w).
- Latin words (SpeechTranscriber) keep their words. A few Apple spellings
change (mei -> main, hoo -> hoon, nahin -> nahi), and Apple's
mid-sentence capitals on common Hindi words are lowered.
- Devanagari digits become 0-9, and a spoken hour before "baje" becomes
digits ("paanch baje" -> "5 baje").
Verified: HinglishRomanizerTests (5 cases) pass in xcodebuild test on an
iOS 27.2 simulator. Word accuracy against the expected casual spelling,
over 45 synthesized Hinglish sentences (Lekha voice, macOS 27.2 Speech):
- DictationTranscriber output: 1.3% -> 82.1%
- clean Devanagari: 100%
- 30 held-out sentences: 100% (93.0% exact spelling)
Latency is about 0.01 ms per sentence (macOS -O) after a 3-6 ms first
call. It adds 0.7 MB in the simulator.
* iOS: Hinglish dictation, Hindi in Latin letters (Experiment, off by default)
Settings › Experiments › Hinglish (Hindi in Latin letters). While it is
on, Hindi dictation is written in Latin letters the way people text it
("meeting kal 5 baje hai"), in the app and in-keyboard dictation alike.
Hindi is also offered in the Hex key's language menu and named
"Hinglish" there and in Settings › Dictation language.
- HinglishSettings (App Group key experiments.hinglish; the launch
argument --experiment-hinglish turns it on in simulator scenes).
- DictationPipeline runs HinglishRomanizer as its first step, only for
Hindi and only while the experiment is on. Learned fixes, custom
vocabulary, the style (#2103) and Lowercase then work on the Latin
words. The new Stages.heard (Latin for Hinglish) is what learning
compares with the inserted text. It replaces the raw transcript, so
Devanagari isn't learned against Latin edits.
- DictationController reads the setting when a capture starts, as it
does for Lowercase. KeyboardLocalDictation reads it at transcription.
Both stay string rules with no model, so the keyboard's memory guard
(#2045) needs no new headroom.
- DictationLanguageSwitch: nativeName/nativeNames return "Hinglish" for
hi while on, and choices(hinglish:) offers hi-IN after the recents
when Apple Speech lists it. KeyboardViewController passes the setting
and adds it to the menu's signature.
- AppleSpeechLanguages.options and DictationLanguageRow name Hindi
"Hinglish" while on.
- zh-Hans strings for the new row. settings-*-on scenes turn it on. The
keyboard fixture puts a --dictation-language missing from its list
first, for the Hinglish menu scene.
Not changed: Apple Speech still picks the module (SpeechTranscriber for
hi-IN where available, which already writes Latin), and nothing changes
while the experiment is off.
Verified: xcodebuild test on an iOS 27.2 simulator (iPhone 17 Pro):
372 tests, 0 failures, 1 skipped. New tests:
- HinglishRomanizerTests.testStylesAndLowercaseApplyToHinglish
- DictationLanguageSwitchTests.testHinglishOffersHindiByThatName
Screenshots of settings-experiments-on, full-keyboard-languages
(--experiment-hinglish --dictation-language hi-IN) and
settings-dictation-on with hi-IN show the toggle, "Hinglish" ticked in
the Hex key's menu, and Dictation language "Hinglish".
63 lines
2.6 KiB
Swift
63 lines
2.6 KiB
Swift
import SwiftUI
|
|
|
|
@main
|
|
struct HEXMobileApp: App {
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
@State private var dictation = DictationController.shared
|
|
@State private var openedFromKeyboard = Self.initialOpenedFromKeyboard
|
|
@State private var showSetup = SettingsSnapshotFixture.showsSetupSheet
|
|
|
|
init() {
|
|
FullKeyboardSettings().applyLaunchArguments()
|
|
TypingLogSettings().applyLaunchArguments()
|
|
HinglishSettings().applyLaunchArguments()
|
|
SettingsSnapshotFixture.applyDefaults()
|
|
}
|
|
|
|
private static var initialOpenedFromKeyboard: Bool {
|
|
let args = ProcessInfo.processInfo.arguments
|
|
guard let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count else {
|
|
return false
|
|
}
|
|
return args[idx + 1].hasPrefix("handoff-")
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil {
|
|
Color.clear
|
|
} else if let keyboardScene = KeyboardSnapshotStage.requestedScene {
|
|
KeyboardSnapshotStage(scene: keyboardScene)
|
|
} else if let fullKeyboardScene = FullKeyboardSnapshotStage.requestedScene {
|
|
FullKeyboardSnapshotStage(scene: fullKeyboardScene)
|
|
} else if let experimentsScene = ExperimentsSnapshotStage.requestedScene {
|
|
ExperimentsSnapshotStage(scene: experimentsScene)
|
|
} else if let hostedScene = HostedKeyboardConversationStage.requestedScene {
|
|
HostedKeyboardConversationStage(scene: hostedScene, dictation: dictation)
|
|
} else {
|
|
ContentView(
|
|
dictation: dictation,
|
|
openedFromKeyboard: $openedFromKeyboard,
|
|
showSetup: $showSetup
|
|
)
|
|
.onOpenURL { url in
|
|
guard let request = KeyboardLaunchRequest(url: url) else { return }
|
|
if case .setup = request {
|
|
openedFromKeyboard = false
|
|
showSetup = true
|
|
} else {
|
|
openedFromKeyboard = true
|
|
}
|
|
dictation.handleKeyboardLaunch(request)
|
|
}
|
|
.onChange(of: scenePhase) { _, phase in
|
|
if phase == .background {
|
|
openedFromKeyboard = false
|
|
} else if phase == .active {
|
|
dictation.endStaleLiveActivities()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|