Renamed the RecordingService protocol in the Recording package target as Capturing.
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 ``Transcribing`` attached at initialization; when either of them fails, the model falls back to the not-recording state.
|
||||
/// ``Capturing`` and ``Transcribing`` attached at initialization; when either of them fails, the model falls back to the not-recording state.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class Model {
|
||||
@@ -41,7 +41,7 @@ extension RecordingView {
|
||||
|
||||
/// The service that captures the audio from a microphone.
|
||||
@ObservationIgnored
|
||||
private let recorder: any RecordingService
|
||||
private let capturer: any Capturing
|
||||
|
||||
/// The task that updates ``elapsedSeconds`` from the measured recording time once per second while recording.
|
||||
@ObservationIgnored
|
||||
@@ -56,15 +56,15 @@ extension RecordingView {
|
||||
/// Creates a model attached to the given recording and transcribing services.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - recorder: The service that captures the audio from a microphone. Defaults to ``DummyRecordingService``.
|
||||
/// - capturer: The service that captures the audio from a microphone. Defaults to ``DummyCapturing``.
|
||||
/// - 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(),
|
||||
capturer: any Capturing = DummyCapturing(),
|
||||
transcribe: any Transcribing = DummyTranscribing(),
|
||||
locale: Binding<Locale> = .constant(.current)
|
||||
) {
|
||||
self.recorder = recorder
|
||||
self.capturer = capturer
|
||||
self.transcribe = transcribe
|
||||
self.locale = locale
|
||||
}
|
||||
@@ -167,12 +167,12 @@ extension RecordingView {
|
||||
switch state {
|
||||
case .recording:
|
||||
startTimer(shouldRestartTimer)
|
||||
startRecorder(shouldRestartTimer)
|
||||
startCapturer(shouldRestartTimer)
|
||||
case .paused:
|
||||
stopTimer()
|
||||
|
||||
Task {
|
||||
try? await recorder.pause()
|
||||
try? await capturer.pause()
|
||||
}
|
||||
case .processing:
|
||||
stopTimer()
|
||||
@@ -213,7 +213,7 @@ private extension RecordingView.Model {
|
||||
}
|
||||
|
||||
do {
|
||||
let audio = try await recorder.stop()
|
||||
let audio = try await capturer.stop()
|
||||
|
||||
transcription = try await transcribe(
|
||||
audio,
|
||||
@@ -228,17 +228,17 @@ private extension RecordingView.Model {
|
||||
state = .notRecording
|
||||
}
|
||||
|
||||
/// Starts the audio capture through the attached ``RecordingService``, falling back to the not-recording state when the service fails.
|
||||
/// Starts the audio capture through the attached ``Capturing``, falling back to the not-recording state when the service fails.
|
||||
///
|
||||
/// - Parameter isNewRecording: Whether a new recording should be started, as opposed to a paused one being resumed.
|
||||
func startRecorder(
|
||||
func startCapturer(
|
||||
_ isNewRecording: Bool
|
||||
) {
|
||||
Task {
|
||||
do {
|
||||
isNewRecording
|
||||
? try await recorder.start()
|
||||
: try await recorder.resume()
|
||||
? try await capturer.start()
|
||||
: try await capturer.resume()
|
||||
} catch {
|
||||
stopTimer()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user