60 lines
1.8 KiB
Swift
60 lines
1.8 KiB
Swift
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
|
|
let transcriber = AudioTranscribingService()
|
|
|
|
// 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
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Models
|
|
|
|
extension ContentView.Model {
|
|
/// A transcription of a processed recording to present in the modal sheet.
|
|
struct Transcription: Identifiable {
|
|
/// The unique identifier of the transcription.
|
|
let id = UUID()
|
|
/// The transcribed text of the processed recording.
|
|
let text: String
|
|
}
|
|
}
|