2026-07-04 15:06:55 +02:00
|
|
|
import Foundation
|
|
|
|
|
import Recording
|
|
|
|
|
|
|
|
|
|
/// A transcribing service with a configurable delay, output, and failure.
|
|
|
|
|
@MainActor
|
|
|
|
|
final class TranscribingMock: Transcribing {
|
2026-07-05 16:16:53 +02:00
|
|
|
|
|
|
|
|
// MARK: Properties
|
2026-07-04 15:06:55 +02:00
|
|
|
|
|
|
|
|
/// The duration of the simulated transcription work.
|
|
|
|
|
var delay: Duration = .seconds(0.2)
|
|
|
|
|
|
|
|
|
|
/// The error the service throws, or `nil` when it should succeed.
|
|
|
|
|
var error: Error?
|
|
|
|
|
|
|
|
|
|
/// The transcription the service returns.
|
|
|
|
|
var transcription = "This is a mocked transcription."
|
2026-07-05 16:16:53 +02:00
|
|
|
|
|
|
|
|
// MARK: Methods
|
2026-07-04 15:06:55 +02:00
|
|
|
|
|
|
|
|
func callAsFunction(
|
|
|
|
|
_ audio: URL,
|
|
|
|
|
locale: Locale
|
|
|
|
|
) async throws -> Transcription {
|
|
|
|
|
try await Task.sleep(for: delay)
|
|
|
|
|
|
|
|
|
|
if let error {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return .init(text: transcription)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|