Implemented the pre-installation of speech model assets for the selected locale for the ContentViewModel view model in the Sample app target.

This commit is contained in:
2026-07-04 15:41:53 +02:00
parent 0ca948272b
commit 7ec49264e6
2 changed files with 29 additions and 0 deletions
@@ -62,6 +62,32 @@ extension ContentView {
}
}
/// Preinstalls the speech model assets for the supported equivalent of ``locale``, so the first transcription in that locale
/// does not have to download them mid-processing.
///
/// Failures are ignored on purpose: the transcribing service installs any missing assets itself as a fallback when a
/// transcription starts.
func preinstallAssets() async {
guard let locale = await SpeechTranscriber.supportedLocale(
equivalentTo: locale
) else {
return
}
let transcriber = SpeechTranscriber(
locale: locale,
preset: .transcription
)
guard let request = try? await AssetInventory.assetInstallationRequest(
supporting: [transcriber]
) else {
return
}
try? await request.downloadAndInstall()
}
/// Returns the localized name of a locale for the locale picker.
///
/// - Parameter locale: The locale to name.
+3
View File
@@ -61,6 +61,9 @@ struct ContentView: View {
.task {
await model.load()
}
.task(id: model.locale) {
await model.preinstallAssets()
}
}
.sheet(item: $model.transcription) { transcription in
NavigationStack {