Implemented the AssetPreinstalling service in the Recording package target.

This commit is contained in:
2026-07-05 13:37:04 +02:00
parent 59b0237638
commit d22a8dda13
4 changed files with 269 additions and 5 deletions
@@ -6,10 +6,15 @@ import Speech
///
/// The service runs the given recorded audio file through a `SpeechAnalyzer` with a `SpeechTranscriber` module, joining the finalized
/// results into the returned transcription. The transcription happens in the locale given at each call or rather in the closest equivalent
/// the transcriber supports. The speech model assets for that locale are downloaded and installed on first use; every transcription after
/// that happens entirely offline.
/// the transcriber supports. Any speech model assets still missing for that locale are installed first through ``AssetPreinstalling``;
/// every transcription after that happens entirely offline.
public struct AudioTranscribing: Transcribing {
// MARK: Properties
/// The preinstalling service that installs any speech model assets still missing when a transcription starts.
private let preinstaller = AssetPreinstalling()
// MARK: Initializers
/// Creates an audio transcribing service.
@@ -46,9 +51,7 @@ public struct AudioTranscribing: Transcribing {
)
do {
if let request = try await AssetInventory.assetInstallationRequest(supporting: [transcriber]) {
try await request.downloadAndInstall()
}
try await preinstaller.install(for: locale)
} catch {
logger.error("The speech model assets for the \"\(locale.identifier, privacy: .public)\" locale failed to install: \(String(describing: error), privacy: .public)")