forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveTranscriptMonitor.swift
More file actions
44 lines (35 loc) · 1.22 KB
/
Copy pathLiveTranscriptMonitor.swift
File metadata and controls
44 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Foundation
/// Dedicated monitor for live transcript segments that doesn't trigger global AppState re-renders.
/// Only views that explicitly observe this class will update when transcript changes.
@MainActor
class LiveTranscriptMonitor: ObservableObject {
static let shared = LiveTranscriptMonitor()
/// Live speaker segments for real-time transcript display
@Published private(set) var segments: [SpeakerSegment] = []
/// Snapshot of segments saved before clear, so the transcript survives recording stop
@Published private(set) var savedSegments: [SpeakerSegment] = []
private init() {}
/// Update segments - called from transcription service
func updateSegments(_ newSegments: [SpeakerSegment]) {
segments = newSegments
}
/// Clear live segments, automatically snapshotting them to savedSegments
func clear() {
if !segments.isEmpty {
savedSegments = segments
}
segments = []
}
/// Clear the saved snapshot (e.g. when user collapses the transcript panel)
func clearSaved() {
savedSegments = []
}
/// Check if there are any segments
var isEmpty: Bool {
segments.isEmpty
}
/// Get the latest transcript text
var latestText: String? {
segments.last?.text
}
}