Added a discard button and error handling to the RecordingView view in the Recording package target.

This commit is contained in:
2026-07-04 15:59:30 +02:00
parent 7ec49264e6
commit b0c6e25639
7 changed files with 339 additions and 14 deletions
@@ -1,5 +1,6 @@
import Foundation
import Observation
import OSLog
import Recording
import Speech
@@ -30,6 +31,13 @@ extension ContentView {
@ObservationIgnored
let capturer: AudioCapturing
/// The logger that records the failures of the speech model asset management.
@ObservationIgnored
private let logger = Logger(
subsystem: Bundle.main.bundleIdentifier ?? "Attendi",
category: "ContentView.Model"
)
/// The service that transcribes the recorded audio into text on device.
@ObservationIgnored
let transcriber: AudioTranscribing
@@ -65,7 +73,9 @@ 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
/// The locale reservations of any other locales are released beforehand: the app transcribes a single locale at a time, and
/// the system only permits a limited number of reservations exceeding it would make the installation request throw.
/// Failures are logged but not surfaced: the transcribing service installs any missing assets itself as a fallback when a
/// transcription starts.
func preinstallAssets() async {
guard let locale = await SpeechTranscriber.supportedLocale(
@@ -74,18 +84,26 @@ extension ContentView {
return
}
for reserved in await AssetInventory.reservedLocales where reserved != locale {
_ = await AssetInventory.release(reservedLocale: reserved)
}
let transcriber = SpeechTranscriber(
locale: locale,
preset: .transcription
)
guard let request = try? await AssetInventory.assetInstallationRequest(
supporting: [transcriber]
) else {
return
}
do {
guard let request = try await AssetInventory.assetInstallationRequest(
supporting: [transcriber]
) else {
return
}
try? await request.downloadAndInstall()
try await request.downloadAndInstall()
} catch {
logger.error("The speech model assets for the \"\(locale.identifier, privacy: .public)\" locale failed to preinstall: \(String(describing: error), privacy: .public)")
}
}
/// Returns the localized name of a locale for the locale picker.