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,4 +1,5 @@
import AVFoundation
import OSLog
import Speech
/// The transcribing service that transcribes recorded audio into text on device.
@@ -23,7 +24,8 @@ public struct AudioTranscribing: Transcribing {
/// - locale: The locale of the spoken language to transcribe.
/// - Returns: The transcription of the recorded audio.
/// - Throws: ``AudioTranscribingError/localeNotSupported`` when the transcriber supports no equivalent of the given locale,
/// or any error thrown while installing the speech model assets, reading the audio file, or analyzing its contents.
/// ``AudioTranscribingError/assetsNotInstalled`` when the speech model assets fail to reserve, download, or install,
/// or any error thrown while reading the audio file or analyzing its contents.
public func callAsFunction(
_ audio: URL,
locale: Locale
@@ -43,8 +45,14 @@ public struct AudioTranscribing: Transcribing {
preset: .transcription
)
if let request = try await AssetInventory.assetInstallationRequest(supporting: [transcriber]) {
try await request.downloadAndInstall()
do {
if let request = try await AssetInventory.assetInstallationRequest(supporting: [transcriber]) {
try await request.downloadAndInstall()
}
} catch {
logger.error("The speech model assets for the \"\(locale.identifier, privacy: .public)\" locale failed to install: \(String(describing: error), privacy: .public)")
throw AudioTranscribingError.assetsNotInstalled
}
let analyzer = SpeechAnalyzer(modules: [transcriber])
@@ -70,6 +78,16 @@ public struct AudioTranscribing: Transcribing {
/// The errors thrown by ``AudioTranscribing``.
public enum AudioTranscribingError: Error {
/// The speech model assets for the locale failed to reserve, download, or install.
case assetsNotInstalled
/// The transcriber supports no equivalent of the locale the transcription was requested with.
case localeNotSupported
}
// MARK: - Constants
/// The logger that records the failures of the audio transcribing service.
private let logger = Logger(
subsystem: "Features.Recording",
category: "AudioTranscribing"
)