2026-07-04 10:32:59 +02:00
|
|
|
import Foundation
|
|
|
|
|
import Observation
|
|
|
|
|
import Recording
|
|
|
|
|
|
|
|
|
|
extension ContentView {
|
|
|
|
|
|
|
|
|
|
/// The observable model that drives ``ContentView``.
|
|
|
|
|
///
|
|
|
|
|
/// The model owns the recording and transcribing services attached to the recording feature, and holds the transcription currently
|
|
|
|
|
/// presented in the view's modal sheet: ``received(_:)`` wraps the transcribed text of a processed recording for presentation, and
|
|
|
|
|
/// ``dismissed()`` clears it when the sheet closes.
|
|
|
|
|
@MainActor
|
|
|
|
|
@Observable
|
|
|
|
|
final class Model {
|
|
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
/// The transcription currently presented in the modal sheet, or `nil` when none is shown.
|
|
|
|
|
var transcription: Transcription?
|
|
|
|
|
|
|
|
|
|
/// The service that captures the audio from the device's microphone.
|
|
|
|
|
@ObservationIgnored
|
|
|
|
|
let recorder = AudioRecordingService()
|
|
|
|
|
|
|
|
|
|
/// The service that transcribes the recorded audio into text on device.
|
|
|
|
|
@ObservationIgnored
|
2026-07-04 12:03:19 +02:00
|
|
|
let transcriber = AudioTranscribing()
|
2026-07-04 10:32:59 +02:00
|
|
|
|
|
|
|
|
// MARK: Methods
|
|
|
|
|
|
|
|
|
|
/// Handles the transcribed text of a processed recording, presenting it in the modal sheet.
|
|
|
|
|
///
|
|
|
|
|
/// - Parameter text: The transcribed text of the processed recording.
|
|
|
|
|
func received(
|
|
|
|
|
_ text: String
|
|
|
|
|
) {
|
|
|
|
|
transcription = .init(text: text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Handles the dismissal of the modal sheet.
|
|
|
|
|
func dismissed() {
|
|
|
|
|
transcription = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|