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:
@@ -21,7 +21,11 @@ extension RecordingView {
|
||||
private(set) var elapsedSeconds: Int = 0
|
||||
|
||||
/// The transcription of the last processed recording, or `nil` when none has been processed yet.
|
||||
private(set) var textTranscription: String?
|
||||
private(set) var transcription: Transcription?
|
||||
|
||||
/// The binding to the locale of the spoken language to transcribe.
|
||||
@ObservationIgnored
|
||||
private let locale: Binding<Locale>
|
||||
|
||||
/// The service that captures the audio from a microphone.
|
||||
@ObservationIgnored
|
||||
@@ -42,12 +46,15 @@ extension RecordingView {
|
||||
/// - Parameters:
|
||||
/// - recorder: The service that captures the audio from a microphone. Defaults to ``DummyRecordingService``.
|
||||
/// - transcribe: The callable service that transcribes the recorded audio into text. Defaults to ``DummyTranscribing``.
|
||||
/// - locale: The binding to the locale of the spoken language to transcribe. Defaults to a constant binding to the user's current locale.
|
||||
init(
|
||||
recorder: any RecordingService = DummyRecordingService(),
|
||||
transcribe: any Transcribing = DummyTranscribing()
|
||||
transcribe: any Transcribing = DummyTranscribing(),
|
||||
locale: Binding<Locale> = .constant(.current)
|
||||
) {
|
||||
self.recorder = recorder
|
||||
self.transcribe = transcribe
|
||||
self.locale = locale
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
@@ -175,7 +182,7 @@ private extension RecordingView.Model {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
/// Processes the recorded input: it stops the audio capture, transcribes the captured audio, and publishes the result in ``textTranscription``;
|
||||
/// Processes the recorded input: it stops the audio capture, transcribes the captured audio, and publishes the result in ``transcription``;
|
||||
/// when finished — or when either service fails — it resets ``elapsedSeconds`` and returns the model to the not-recording state.
|
||||
func processInput() async {
|
||||
guard state == .processing else {
|
||||
@@ -185,12 +192,12 @@ private extension RecordingView.Model {
|
||||
do {
|
||||
let audio = try await recorder.stop()
|
||||
|
||||
textTranscription = try await transcribe(
|
||||
transcription = try await transcribe(
|
||||
audio,
|
||||
locale: .current
|
||||
).text
|
||||
locale: locale.wrappedValue
|
||||
)
|
||||
} catch {
|
||||
textTranscription = nil
|
||||
transcription = nil
|
||||
}
|
||||
|
||||
elapsedSeconds = 0
|
||||
@@ -218,14 +225,14 @@ private extension RecordingView.Model {
|
||||
|
||||
/// Starts the timer task, which increments ``elapsedSeconds`` once per second until it is cancelled. Any previously running timer task is cancelled first.
|
||||
///
|
||||
/// - Parameter shouldRestartTimer: Whether ``elapsedSeconds`` and ``textTranscription`` should be cleared before the timer starts,
|
||||
/// - Parameter shouldRestartTimer: Whether ``elapsedSeconds`` and ``transcription`` should be cleared before the timer starts,
|
||||
/// which is the case for a new recording as opposed to one resuming from a pause.
|
||||
func startTimer(
|
||||
_ shouldRestartTimer: Bool
|
||||
) {
|
||||
if shouldRestartTimer {
|
||||
elapsedSeconds = 0
|
||||
textTranscription = nil
|
||||
transcription = nil
|
||||
}
|
||||
|
||||
taskTimer?.cancel()
|
||||
|
||||
Reference in New Issue
Block a user