Propagated the Transcription type and locale binding through the RecordingView view and its view model in the Recording package target.

This commit is contained in:
2026-07-04 12:11:24 +02:00
parent 68c070948e
commit 20cbda7b27
6 changed files with 47 additions and 30 deletions
@@ -13,8 +13,8 @@ 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
/// The closure invoked with the transcription of every processed recording.
private let onTranscription: (Transcription) -> Void
// MARK: Initializers
@@ -23,15 +23,18 @@ public struct RecordingView: View {
/// - 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.
/// - locale: The binding to the locale of the spoken language to transcribe.
/// - onTranscription: The closure invoked with the transcription of every processed recording. Defaults to a closure that does nothing.
public init(
recorder: any RecordingService,
transcriber: any Transcribing,
onTranscription: @escaping (String) -> Void = { _ in }
locale: Binding<Locale>,
onTranscription: @escaping (Transcription) -> Void
) {
self.model = .init(
recorder: recorder,
transcribe: transcriber
transcribe: transcriber,
locale: locale
)
self.onTranscription = onTranscription
}
@@ -101,7 +104,7 @@ public struct RecordingView: View {
)
}
.onChange(
of: model.textTranscription,
of: model.transcription,
initial: false
) { _, newValue in
if let newValue {
@@ -130,6 +133,9 @@ private enum Constant {
) {
RecordingView(
recorder: DummyRecordingService(),
transcriber: DummyTranscribing()
)
transcriber: DummyTranscribing(),
locale: .constant(.current)
) { _ in
// On transcription closure.
}
}