// What every microphone listens for, read from the core just before each// session: `read.voiceContext` ranks the person's manual words and the names// in their databases in Rust, and answers the person's language. A failed// optional read leaves dictation available with no hints and the device's// language.importCottonKitimportFoundationpublicenumVoiceBias { @MainActorpublicstaticfunc hints(core: any CottonCalling) async -> DictationHints {// The device's own language model rides with the hints when this// process has loaded one; the first microphone starts the keeper.let keeper = VoiceModelKeeper.shared keeper.ensure()var hints = (try? await core.callJSON(CottonMethod.readVoiceContext)).map { hints($0) } ?? DictationHints() hints.model = await keeper.model(for: hints.locale)return hints }/// The answer's hints, in the core's order and exact spelling:/// `biasGroups` — `[{tag, terms}]`, the ranked hundred split by why each/// term is there (manual, people, places, projects, screen) — tag by tag.staticfunc hints(_ read: JSONValue) -> DictationHints {let groups = read.list("biasGroups").compactMap { group -> DictationHints.Group? inguardlet tag = group["tag"]?.string else { returnnil }returnDictationHints.Group(tag: tag, terms: terms(group.list("terms"))) }returnDictationHints(groups: groups, language: read["language"]?.string) }privatestaticfunc terms(_ list: [JSONValue]) -> [String] {// Nonblank spaces inside a term are the person's, and kept. list.compactMap(\.string).filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } }}@MainActorpublicextensionBodyDictation {/// Read just before opening this session, even while its screen stays up. @discardableResultfunc start(core: any CottonCalling) async -> DictationOutcome? {await start(hints: VoiceBias.hints(core: core)) }}