54 lines
1.5 KiB
Swift
54 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
/// A service that captures audio from a microphone for the Recording feature.
|
|
///
|
|
/// ``RecordingView`` attaches the service to its model at initialization, so the audio capture can be swapped without touching the feature's
|
|
/// state machine — for example, with a real microphone backend in the app, or with a mock in unit tests.
|
|
public protocol RecordingService: Sendable {
|
|
|
|
/// Starts a new audio recording from the microphone.
|
|
func start() async throws
|
|
|
|
/// Pauses the ongoing recording.
|
|
func pause() async throws
|
|
|
|
/// Resumes a paused recording.
|
|
func resume() async throws
|
|
|
|
/// Stops the recording.
|
|
///
|
|
/// - Returns: The audio captured since the recording started.
|
|
func stop() async throws -> Data
|
|
|
|
}
|
|
|
|
// MARK: - Services
|
|
|
|
/// The recording service used by default, which simulates the audio capture without touching a microphone.
|
|
public struct SimulatedRecordingService: RecordingService {
|
|
|
|
// MARK: Initializers
|
|
|
|
/// Creates a simulated recording service.
|
|
public init() {}
|
|
|
|
// MARK: Methods
|
|
|
|
/// Simulates the start of an audio recording.
|
|
public func start() async throws {}
|
|
|
|
/// Simulates the pause of an ongoing recording.
|
|
public func pause() async throws {}
|
|
|
|
/// Simulates the resumption of a paused recording.
|
|
public func resume() async throws {}
|
|
|
|
/// Simulates the stop of a recording.
|
|
///
|
|
/// - Returns: An empty audio payload.
|
|
public func stop() async throws -> Data {
|
|
.init()
|
|
}
|
|
|
|
}
|