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:
@@ -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.
|
/// Returns the localized name of a locale for the locale picker.
|
||||||
///
|
///
|
||||||
/// - Parameter locale: The locale to name.
|
/// - Parameter locale: The locale to name.
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ struct ContentView: View {
|
|||||||
.task {
|
.task {
|
||||||
await model.load()
|
await model.load()
|
||||||
}
|
}
|
||||||
|
.task(id: model.locale) {
|
||||||
|
await model.preinstallAssets()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.sheet(item: $model.transcription) { transcription in
|
.sheet(item: $model.transcription) { transcription in
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
|
|||||||
Reference in New Issue
Block a user