Added the "onTranscription" closure to the RecordingView view in the Recording package target.

This commit is contained in:
2026-07-03 23:45:25 +02:00
parent d7d50492e6
commit f56ca3d8ff
@@ -12,22 +12,28 @@ public struct RecordingView: View {
/// The model that owns the recording state and drives the view's controls. /// The model that owns the recording state and drives the view's controls.
@State private var model: Model @State private var model: Model
/// The closure invoked with the transcribed text of every processed recording.
private let onTranscription: (String) -> Void
// MARK: Initializers // MARK: Initializers
/// Creates a recording view in the not-recording state, attached to the given recording and transcribing services. /// Creates a recording view in the not-recording state, attached to the given recording and transcribing services.
/// ///
/// - Parameters: /// - Parameters:
/// - recorder: The service that captures the audio from a microphone. /// - recorder: The service that captures the audio from a microphone.
/// - transcriber: The service that transcribes the recorded audio into text. /// - transcriber: The service that transcribes the recorded audio into text.
/// - onTranscription: The closure invoked with the transcribed text of every processed recording. Defaults to a closure that does nothing.
public init( public init(
recorder: any RecordingService, recorder: any RecordingService,
transcriber: any TranscribingService transcriber: any TranscribingService,
onTranscription: @escaping (String) -> Void = { _ in }
) { ) {
self.model = .init( self.model = .init(
recorder: recorder, recorder: recorder,
transcriber: transcriber transcriber: transcriber
) )
self.onTranscription = onTranscription
} }
// MARK: Body // MARK: Body
@@ -88,6 +94,14 @@ public struct RecordingView: View {
shouldRestartTimer: oldValue == .notRecording shouldRestartTimer: oldValue == .notRecording
) )
} }
.onChange(
of: model.textTranscription,
initial: false
) { _, newValue in
if let newValue {
onTranscription(newValue)
}
}
} }
} }