2026-07-03 20:05:11 +02:00
|
|
|
import Recording
|
2026-07-03 15:11:33 +02:00
|
|
|
import SwiftUI
|
|
|
|
|
|
2026-07-03 20:05:11 +02:00
|
|
|
/// The root view of the Attendi sample app.
|
|
|
|
|
///
|
2026-07-03 23:48:16 +02:00
|
|
|
/// The view hosts the `RecordingView` feature from the `Recording` target of the `Features` package, which drives the whole recording flow,
|
|
|
|
|
/// and presents the transcribed text of every processed recording in a modal sheet.
|
2026-07-03 15:11:33 +02:00
|
|
|
struct ContentView: View {
|
2026-07-03 20:05:11 +02:00
|
|
|
|
2026-07-03 23:48:16 +02:00
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
/// The transcription currently presented in the modal sheet, or `nil` when none is shown.
|
|
|
|
|
@State private var transcription: Transcription?
|
|
|
|
|
|
2026-07-03 20:05:11 +02:00
|
|
|
// MARK: Body
|
|
|
|
|
|
2026-07-03 23:48:16 +02:00
|
|
|
/// The content of the view: the recording feature's view, attached to the microphone-backed recording service and the on-device speech
|
|
|
|
|
/// transcribing service, with the transcribed text of every processed recording presented in a modal sheet.
|
2026-07-03 15:11:33 +02:00
|
|
|
var body: some View {
|
2026-07-03 21:33:46 +02:00
|
|
|
RecordingView(
|
2026-07-03 22:01:17 +02:00
|
|
|
recorder: AudioRecordingService(),
|
2026-07-03 22:13:16 +02:00
|
|
|
transcriber: AudioTranscribingService()
|
2026-07-03 23:48:16 +02:00
|
|
|
) { text in
|
|
|
|
|
transcription = .init(text: text)
|
|
|
|
|
}
|
|
|
|
|
.sheet(item: $transcription) { transcription in
|
|
|
|
|
NavigationStack {
|
|
|
|
|
ScrollView {
|
|
|
|
|
Text(transcription.text)
|
|
|
|
|
.frame(
|
|
|
|
|
maxWidth: .infinity,
|
|
|
|
|
alignment: .leading
|
|
|
|
|
)
|
|
|
|
|
.padding()
|
|
|
|
|
}
|
|
|
|
|
.navigationTitle("Transcription")
|
|
|
|
|
#if !os(macOS)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
|
#endif
|
|
|
|
|
.toolbar {
|
|
|
|
|
Button("Done") {
|
|
|
|
|
self.transcription = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.presentationDetents([.medium, .large])
|
|
|
|
|
}
|
2026-07-03 15:11:33 +02:00
|
|
|
}
|
2026-07-03 20:05:11 +02:00
|
|
|
|
2026-07-03 15:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-03 23:48:16 +02:00
|
|
|
// MARK: - Models
|
|
|
|
|
|
|
|
|
|
/// A transcription of a processed recording to present in the modal sheet.
|
|
|
|
|
private struct Transcription: Identifiable {
|
|
|
|
|
/// The unique identifier of the transcription.
|
|
|
|
|
let id = UUID()
|
|
|
|
|
/// The transcribed text of the processed recording.
|
|
|
|
|
let text: String
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 20:05:11 +02:00
|
|
|
// MARK: - Previews
|
|
|
|
|
|
|
|
|
|
#Preview(
|
|
|
|
|
"Content view"
|
|
|
|
|
) {
|
2026-07-03 15:11:33 +02:00
|
|
|
ContentView()
|
|
|
|
|
}
|