Added the "onTranscription" closure to the RecordingView view in the Recording package target.
This commit is contained in:
@@ -12,22 +12,28 @@ public struct RecordingView: View {
|
||||
|
||||
/// The model that owns the recording state and drives the view's controls.
|
||||
@State private var model: Model
|
||||
|
||||
|
||||
/// The closure invoked with the transcribed text of every processed recording.
|
||||
private let onTranscription: (String) -> Void
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
|
||||
/// Creates a recording view in the not-recording state, attached to the given recording and transcribing services.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - recorder: The service that captures the audio from a microphone.
|
||||
/// - 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(
|
||||
recorder: any RecordingService,
|
||||
transcriber: any TranscribingService
|
||||
transcriber: any TranscribingService,
|
||||
onTranscription: @escaping (String) -> Void = { _ in }
|
||||
) {
|
||||
self.model = .init(
|
||||
recorder: recorder,
|
||||
transcriber: transcriber
|
||||
)
|
||||
self.onTranscription = onTranscription
|
||||
}
|
||||
|
||||
// MARK: Body
|
||||
@@ -88,6 +94,14 @@ public struct RecordingView: View {
|
||||
shouldRestartTimer: oldValue == .notRecording
|
||||
)
|
||||
}
|
||||
.onChange(
|
||||
of: model.textTranscription,
|
||||
initial: false
|
||||
) { _, newValue in
|
||||
if let newValue {
|
||||
onTranscription(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user