// The operating system's on-device speech model, chosen and fetched in ONE// place: which locale a module can listen in, and the language's model, which// the system downloads the first time it is asked for (Apple's download; it// carries no audio).//// Live dictation in the app (`CottonUI/Capture/SystemSpeechRecogniser.swift`,// DictationTranscriber over the microphone) uses it and keeps no copy. A// second copy is how two answers to "does this device have English" drift// apart.importFoundationimportSpeech@available(iOS 26.0, macOS 26.0, *)publicenumSpeechModel {/// The locale `module` listens in for `wanted`, or nil when the system has/// no model for that language at all.////// The whole locale first (language and region, so an Indian English/// speaker gets the Indian English model), then the language alone, which/// lets the system pick the region it has.publicstaticfunc locale<Module: LocaleDependentSpeechModule>( _ module: Module.Type, for wanted: Locale ) async -> Locale? {iflet found = await module.supportedLocale(equivalentTo: wanted) { return found }guardlet language = wanted.language.languageCode else { returnnil }returnawait module.supportedLocale(equivalentTo: Locale(languageCode: language)) }/// Make sure the models `modules` need are on this device, fetching them/// the first time. Returns at once when they are already installed.publicstaticfunc install(_ modules: [any SpeechModule]) asyncthrows {iflet request = tryawaitAssetInventory.assetInstallationRequest(supporting: modules) {tryawait request.downloadAndInstall() } }}