Made the transcribing callable and per-call for the transcribing protocol in the Recording package target.
This commit is contained in:
@@ -7,7 +7,7 @@ extension RecordingView {
|
||||
///
|
||||
/// The model implements the recording flow as a ``State`` machine: it exposes the visibility and icon of the view's controls for the current state, counts the
|
||||
/// elapsed recording time, and processes the recorded input once it is sent. The audio capture and its transcription are delegated to the
|
||||
/// ``RecordingService`` and ``TranscribingService`` attached at initialization; when either of them fails, the model falls back to the not-recording state.
|
||||
/// ``RecordingService`` and ``Transcribing`` attached at initialization; when either of them fails, the model falls back to the not-recording state.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class Model {
|
||||
@@ -31,9 +31,9 @@ extension RecordingView {
|
||||
@ObservationIgnored
|
||||
private var taskTimer: Task<Void, Never>?
|
||||
|
||||
/// The service that transcribes the recorded audio into text.
|
||||
/// The callable service that transcribes the recorded audio into text.
|
||||
@ObservationIgnored
|
||||
private let transcriber: any TranscribingService
|
||||
private let transcribe: any Transcribing
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
@@ -41,13 +41,13 @@ extension RecordingView {
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - recorder: The service that captures the audio from a microphone. Defaults to ``DummyRecordingService``.
|
||||
/// - transcriber: The service that transcribes the recorded audio into text. Defaults to ``DummyTranscribingService``.
|
||||
/// - transcribe: The callable service that transcribes the recorded audio into text. Defaults to ``DummyTranscribing``.
|
||||
init(
|
||||
recorder: any RecordingService = DummyRecordingService(),
|
||||
transcriber: any TranscribingService = DummyTranscribingService()
|
||||
transcribe: any Transcribing = DummyTranscribing()
|
||||
) {
|
||||
self.recorder = recorder
|
||||
self.transcriber = transcriber
|
||||
self.transcribe = transcribe
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
@@ -185,7 +185,10 @@ private extension RecordingView.Model {
|
||||
do {
|
||||
let audio = try await recorder.stop()
|
||||
|
||||
textTranscription = try await transcriber.transcribe(audio)
|
||||
textTranscription = try await transcribe(
|
||||
audio,
|
||||
locale: .current
|
||||
).text
|
||||
} catch {
|
||||
textTranscription = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user