Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

feat(meeting): live transcription and clickable speaker naming

Shreeraman A K5fdffdee3c1b
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveBoundedQueue.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveBoundedQueue.swift
new file mode 100644
index 00000000..c09c8e57
--- /dev/null
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveBoundedQueue.swift
@@ -0,0 +1,51 @@
+import Foundation
+
+/// Bounded, drop-oldest queue handing capture-thread audio off to a background worker without ever
+/// blocking the capture callback. Mirrors `MeetingAudioChunkWriter`'s bounded-slot philosophy, but
+/// drops the oldest element instead of rejecting the newest: a dropped live sample degrades a
+/// transcript, not the recording, so newer audio is worth more than older audio here.
+final nonisolated class MeetingLiveBoundedQueue<Element>: @unchecked Sendable {
+ private let lock = NSLock()
+ private var buffer: [Element] = []
+ private let capacity: Int
+ private var droppedCount = 0
+
+ init(capacity: Int) {
+ self.capacity = max(1, capacity)
+ }
+
+ /// Never blocks. Returns true when enqueueing dropped an older element.
+ @discardableResult
+ func enqueue(_ element: Element) -> Bool {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ var dropped = false
+ if self.buffer.count >= self.capacity {
+ self.buffer.removeFirst()
+ self.droppedCount += 1
+ dropped = true
+ }
+ self.buffer.append(element)
+ return dropped
+ }
+
+ func drainAll() -> [Element] {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ defer { self.buffer.removeAll(keepingCapacity: true) }
+ return self.buffer
+ }
+
+ var count: Int {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ return self.buffer.count
+ }
+
+ func takeDroppedCount() -> Int {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ defer { self.droppedCount = 0 }
+ return self.droppedCount
+ }
+}
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift
new file mode 100644
index 00000000..c0923381
--- /dev/null
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift
@@ -0,0 +1,159 @@
+import AVFoundation
+import CoreMedia
+import Foundation
+
+/// "You" is the microphone track, "Them" is the application-audio track. No diarization live —
+/// the offline pipeline resolves real speaker identity and replaces this transcript on completion.
+nonisolated enum MeetingLiveSpeaker: Sendable, Equatable {
+ case you
+ case them
+}
+
+nonisolated enum MeetingLiveAvailability: Sendable, Equatable {
+ case unavailable(reason: String)
+ case degraded(reason: String)
+ case available
+}
+
+nonisolated struct MeetingLiveUtterance: Identifiable, Sendable, Equatable {
+ var id: UUID
+ var speaker: MeetingLiveSpeaker
+ var text: String
+ /// Session-relative seconds, derived from capture PTS — never from arrival order.
+ var start: TimeInterval
+ var end: TimeInterval
+}
+
+/// In-memory only. Never written into `MeetingSession.transcriptSegments`, so it can never reach
+/// the manifest, Copy Transcript, or Export — those all read a `MeetingSession` value, a type this
+/// struct cannot become.
+nonisolated struct MeetingLiveTranscriptSnapshot: Sendable, Equatable {
+ var utterances: [MeetingLiveUtterance] = []
+ var partials: [MeetingLiveSpeaker: String] = [:]
+ var availability: MeetingLiveAvailability = .unavailable(reason: "Live captions have not started.")
+
+ static let empty = MeetingLiveTranscriptSnapshot()
+
+ /// Inserts keeping `utterances` sorted by `start` — two engines finalize independently, so a
+ /// later-arriving utterance with an earlier PTS must still land in the right place.
+ func inserting(_ utterance: MeetingLiveUtterance) -> MeetingLiveTranscriptSnapshot {
+ var copy = self
+ let index = copy.utterances.firstIndex { $0.start > utterance.start } ?? copy.utterances.count
+ copy.utterances.insert(utterance, at: index)
+ return copy
+ }
+
+ /// Each engine returns the whole growing partial, not a delta — this replaces, never appends.
+ func settingPartial(_ text: String?, for speaker: MeetingLiveSpeaker) -> MeetingLiveTranscriptSnapshot {
+ var copy = self
+ if let text, !text.isEmpty {
+ copy.partials[speaker] = text
+ } else {
+ copy.partials.removeValue(forKey: speaker)
+ }
+ return copy
+ }
+
+ func settingAvailability(_ availability: MeetingLiveAvailability) -> MeetingLiveTranscriptSnapshot {
+ var copy = self
+ copy.availability = availability
+ return copy
+ }
+}
+
+nonisolated enum MeetingLiveTimeConversion {
+ /// Mirrors the batch pipeline: session time is capture PTS relative to the capture origin,
+ /// clamped at zero. Never derived from converted-sample counts or wall-clock arrival time.
+ static func sessionSeconds(pts: CMTime, origin: CMTime) -> TimeInterval {
+ guard pts.isValid, pts.isNumeric, origin.isValid, origin.isNumeric else { return 0 }
+ return max(0, CMTimeGetSeconds(pts - origin))
+ }
+}
+
+/// Thread-safe, set-once-per-session capture origin shared by both tracks so "You" and "Them"
+/// timestamps land on the same clock.
+final nonisolated class MeetingLiveOriginBox: @unchecked Sendable {
+ private let lock = NSLock()
+ private var origin: CMTime?
+
+ @discardableResult
+ func establish(_ pts: CMTime) -> CMTime {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ if let existing = self.origin {
+ if pts < existing { self.origin = pts }
+ return self.origin!
+ }
+ self.origin = pts
+ return pts
+ }
+
+ var current: CMTime? {
+ self.lock.lock()
+ defer { self.lock.unlock() }
+ return self.origin
+ }
+}
+
+/// Echo suppression: on speakers, the far end bleeds into the microphone track. This is text-only
+/// (the offline signal scorer needs data live capture can't produce), comparing a mic utterance
+/// against recently finalized "Them" text.
+nonisolated enum MeetingLiveEchoFilter {
+ static func recentThemText(
+ from themUtterances: [MeetingLiveUtterance],
+ before cutoff: TimeInterval,
+ windowSeconds: TimeInterval
+ ) -> String {
+ themUtterances
+ .filter { $0.end > cutoff - windowSeconds && $0.start < cutoff }
+ .sorted { $0.start < $1.start }
+ .map(\.text)
+ .joined(separator: " ")
+ }
+
+ static func shouldSuppress(micText: String, recentThemText: String) -> Bool {
+ guard !recentThemText.isEmpty else { return false }
+ return MeetingEchoDetector.isLikelyEcho(micText: micText, remoteText: recentThemText)
+ }
+}
+
+/// Copies PCM data out of a `CMSampleBuffer` immediately so nothing captured on the capture queue
+/// outlives this call. Never throws into the capture callback — invalid buffers are simply dropped.
+nonisolated enum MeetingLiveSampleCopy {
+ struct Sample: @unchecked Sendable {
+ let buffer: AVAudioPCMBuffer
+ let pts: CMTime
+ let duration: CMTime
+ }
+
+ static func copy(_ sampleBuffer: CMSampleBuffer) -> Sample? {
+ guard CMSampleBufferIsValid(sampleBuffer), CMSampleBufferDataIsReady(sampleBuffer) else { return nil }
+ guard let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer),
+ let streamDescription = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription),
+ let sourceFormat = AVAudioFormat(streamDescription: streamDescription)
+ else { return nil }
+
+ let frameCount = AVAudioFrameCount(CMSampleBufferGetNumSamples(sampleBuffer))
+ guard frameCount > 0,
+ let buffer = AVAudioPCMBuffer(pcmFormat: sourceFormat, frameCapacity: frameCount)
+ else { return nil }
+ buffer.frameLength = frameCount
+
+ let status = CMSampleBufferCopyPCMDataIntoAudioBufferList(
+ sampleBuffer,
+ at: 0,
+ frameCount: Int32(frameCount),
+ into: buffer.mutableAudioBufferList
+ )
+ guard status == noErr else { return nil }
+
+ let pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
+ guard pts.isValid, pts.isNumeric else { return nil }
+
+ var duration = CMSampleBufferGetDuration(sampleBuffer)
+ if !duration.isValid || !duration.isNumeric || duration <= .zero {
+ duration = CMTime(value: CMTimeValue(frameCount), timescale: CMTimeScale(sourceFormat.sampleRate.rounded()))
+ }
+ return Sample(buffer: buffer, pts: pts, duration: duration)
+ }
+}
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift
new file mode 100644
index 00000000..14f8df62
--- /dev/null
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift
@@ -0,0 +1,328 @@
+import AVFoundation
+import CoreMedia
+import Foundation
+#if arch(arm64)
+@preconcurrency import CoreML
+import FluidAudio
+import os
+
+/// Drives one `StreamingEouAsrManager` for one capture track. Two instances are required — the
+/// manager holds a single decoder and endpointing state, so interleaving two audio sources would
+/// corrupt both transcripts.
+///
+/// Audio arrives via the nonisolated `offer(_:)`, called synchronously from the capture-tee copy
+/// (never from the SCStream callback itself). A polling drain loop pulls off the bounded queue and
+/// does all FluidAudio work on this actor, off the capture path entirely.
+actor MeetingLiveTrackEngine {
+ typealias PartialHandler = @Sendable (MeetingAudioTrackKind, String, CMTime, CMTime) -> Void
+ typealias UtteranceHandler = @Sendable (MeetingAudioTrackKind, String, CMTime, CMTime) -> Void
+ typealias DegradedHandler = @Sendable (MeetingAudioTrackKind, String) -> Void
+ typealias ReadyHandler = @Sendable (MeetingAudioTrackKind) -> Void
+
+ private let kind: MeetingAudioTrackKind
+ /// Sized to ride out first-inference CoreML warmup without dropping audio: at the ~10.7ms
+ /// microphone buffers observed in practice this holds ~5.5s, and app-audio buffers twice that.
+ /// A 24-slot queue held only ~0.25s and shed 5s of meeting-opening audio during warmup.
+ nonisolated let queue = MeetingLiveBoundedQueue<MeetingLiveSampleCopy.Sample>(capacity: 512)
+ private static let chunkSize: StreamingChunkSize = .ms160
+ /// The recognizer buffers a full chunk before it can decode it, so the speech behind the first
+ /// token started at least one chunk before the audio we were feeding when that token arrived.
+ private static let decoderLookback = CMTime(value: CMTimeValue(chunkSize.durationMs), timescale: 1000)
+ private let manager: StreamingEouAsrManager
+ private let targetFormat = AVAudioFormat(
+ commonFormat: .pcmFormatFloat32, sampleRate: 16_000, channels: 1, interleaved: false
+ )!
+
+ private var converter: AVAudioConverter?
+ private var converterSourceFormat: AVAudioFormat?
+ private var utteranceStartPTS: CMTime?
+ private var lastConsumedPTS: CMTime?
+ private var currentFeedPTS: CMTime?
+ private var lastUtteranceEndPTS: CMTime?
+ private var pendingResync = false
+ private var drainTask: Task<Void, Never>?
+ private var loadTask: Task<Void, Never>?
+ private var isModelReady = false
+
+ private var diagSamplesConsumed = 0
+ private var diagSecondsConsumed: Double = 0
+ private var diagDrops = 0
+ private var diagPartials = 0
+ private var diagUtterances = 0
+ private var diagLastFlowLog: Double = 0
+ private var diagLastEouUptime: Double?
+
+ private var diagLabel: String { self.kind == .microphone ? "MIC" : "APP" }
+
+ private func diag(_ message: String) {
+ DebugLogger.shared.info("[live/\(self.diagLabel)] \(message)", source: "MeetingLive")
+ }
+
+ private var onPartial: PartialHandler?
+ private var onUtterance: UtteranceHandler?
+ private var onDegraded: DegradedHandler?
+ private var onReady: ReadyHandler?
+
+ init(kind: MeetingAudioTrackKind) {
+ self.kind = kind
+ self.manager = StreamingEouAsrManager(chunkSize: Self.chunkSize)
+ }
+
+ func configure(
+ onPartial: @escaping PartialHandler,
+ onUtterance: @escaping UtteranceHandler,
+ onDegraded: @escaping DegradedHandler,
+ onReady: @escaping ReadyHandler
+ ) {
+ self.onPartial = onPartial
+ self.onUtterance = onUtterance
+ self.onDegraded = onDegraded
+ self.onReady = onReady
+ }
+
+ func start() async {
+ guard self.drainTask == nil else { return }
+ let manager = self.manager
+ let kind = self.kind
+ // Wired synchronously before load/drain start so no decode result can race ahead of it.
+ await self.installCallbacks()
+ self.loadTask = Task { [weak self] in
+ guard let self else { return }
+ do {
+ try Task.checkCancellation()
+ // Shares FluidAudio's default cache dir, so a Parakeet Flash download for
+ // dictation already satisfies this — first-run cost is paid at most once.
+ try await manager.loadModelsFromHuggingFace()
+ guard !Task.isCancelled else { return }
+ await self.warmUp()
+ guard !Task.isCancelled else { return }
+ await self.markReady()
+ } catch {
+ guard !Task.isCancelled else { return }
+ await self.markLoadFailed(kind: kind, error: error)
+ }
+ }
+ self.drainTask = Task { [weak self] in await self?.drainLoop() }
+ }
+
+ func stop() async {
+ self.loadTask?.cancel()
+ self.drainTask?.cancel()
+ await self.drainTask?.value
+ self.drainTask = nil
+ await self.manager.reset()
+ }
+
+ /// Fast, synchronous, non-blocking hand-off from the capture tee. On saturation the queue drops
+ /// the oldest sample, which makes the in-flight utterance untrustworthy — reset and degrade.
+ nonisolated func offer(_ sample: MeetingLiveSampleCopy.Sample) {
+ let dropped = self.queue.enqueue(sample)
+ if dropped {
+ Task { await self.noteDrop() }
+ }
+ }
+
+ private func installCallbacks() async {
+ await self.manager.setEouCallback { [weak self] transcript in
+ Task { await self?.handleEOU(transcript) }
+ }
+ await self.manager.setPartialTranscriptCallback { [weak self] transcript in
+ Task { await self?.handlePartial(transcript) }
+ }
+ }
+
+ /// First CoreML inference on these models costs seconds. Paying it here on silence — before
+ /// `isModelReady` opens the drain loop — keeps the warmup stall from backing up real capture
+ /// audio, which previously overflowed the queue and shed the first ~5s of every meeting.
+ private func warmUp() async {
+ let frames = AVAudioFrameCount(self.targetFormat.sampleRate)
+ guard let silence = AVAudioPCMBuffer(pcmFormat: self.targetFormat, frameCapacity: frames) else { return }
+ silence.frameLength = frames
+ if let channel = silence.floatChannelData?[0] {
+ channel.update(repeating: 0, count: Int(frames))
+ }
+ let started = ProcessInfo.processInfo.systemUptime
+ do {
+ try await self.manager.appendAudio(silence)
+ try await self.manager.processBufferedAudio()
+ } catch {
+ self.diag("warmup failed (continuing): \(error)")
+ }
+ await self.manager.reset()
+ self.diag(String(format: "warmup complete in %.2fs", ProcessInfo.processInfo.systemUptime - started))
+ }
+
+ private func markReady() {
+ self.isModelReady = true
+ self.diag("model ready")
+ self.onReady?(self.kind)
+ }
+
+ private func markLoadFailed(kind: MeetingAudioTrackKind, error: Error) {
+ self.diag("model load FAILED: \(error)")
+ self.onDegraded?(kind, "Live captions could not load: \(error.localizedDescription)")
+ }
+
+ private func drainLoop() async {
+ while !Task.isCancelled {
+ guard self.isModelReady else {
+ try? await Task.sleep(nanoseconds: 100_000_000)
+ continue
+ }
+ let samples = self.queue.drainAll()
+ guard !samples.isEmpty else {
+ try? await Task.sleep(nanoseconds: 20_000_000)
+ continue
+ }
+ await self.applyPendingResyncIfNeeded()
+ for sample in samples where !Task.isCancelled {
+ await self.consume(sample)
+ }
+ }
+ }
+
+ private func consume(_ sample: MeetingLiveSampleCopy.Sample) async {
+ guard let converted = self.convert(sample.buffer) else {
+ self.diag("convert FAILED (sr=\(sample.buffer.format.sampleRate) ch=\(sample.buffer.format.channelCount))")
+ return
+ }
+ self.currentFeedPTS = sample.pts
+ self.lastConsumedPTS = sample.pts + sample.duration
+ self.diagSamplesConsumed += 1
+ self.diagSecondsConsumed += sample.duration.seconds
+ self.logFlowIfDue()
+ do {
+ try await self.manager.appendAudio(converted)
+ try await self.manager.processBufferedAudio()
+ } catch {
+ self.diag("appendAudio/process error: \(error)")
+ self.onDegraded?(self.kind, "Live captions hit an error and resynced.")
+ await self.resetUtterance()
+ }
+ }
+
+ /// Once every 5s of wall clock: proves audio is still reaching the recognizer, and how long the
+ /// current utterance has been open without an endpoint.
+ private func logFlowIfDue() {
+ let now = ProcessInfo.processInfo.systemUptime
+ guard now - self.diagLastFlowLog >= 5 else { return }
+ self.diagLastFlowLog = now
+ let openFor = self.utteranceStartPTS.map { start in
+ (self.lastConsumedPTS ?? start).seconds - start.seconds
+ } ?? 0
+ let sinceEou = self.diagLastEouUptime.map { now - $0 }
+ self.diag(String(
+ format: "flow chunks=%d audio=%.1fs openUtterance=%.1fs partials=%d utterances=%d drops=%d sinceEOU=%@",
+ self.diagSamplesConsumed, self.diagSecondsConsumed, openFor,
+ self.diagPartials, self.diagUtterances, self.diagDrops,
+ sinceEou.map { String(format: "%.1fs", $0) } ?? "never"
+ ))
+ }
+
+ /// The recognizer only emits tokens once it has decoded speech, so the first partial — not the
+ /// first audio buffer — marks where this utterance actually begins. Anchoring on audio instead
+ /// swallowed every second of preceding silence into the utterance's span.
+ private func handlePartial(_ text: String) {
+ if self.utteranceStartPTS == nil {
+ guard let feed = self.currentFeedPTS else { return }
+ let backdated = feed - Self.decoderLookback
+ // Backdating must not reach behind the utterance that just closed, or consecutive turns
+ // render as overlapping spans.
+ self.utteranceStartPTS = self.lastUtteranceEndPTS.map { max(backdated, $0) } ?? backdated
+ }
+ guard let start = self.utteranceStartPTS else { return }
+ let end = self.lastConsumedPTS ?? start
+ self.diagPartials += 1
+ if self.diagPartials % 10 == 1 {
+ self.diag("partial #\(self.diagPartials) chars=\(text.count) tail=…\(String(text.suffix(60)))")
+ }
+ self.onPartial?(self.kind, text, start, end)
+ }
+
+ private func handleEOU(_ text: String) async {
+ let start = self.utteranceStartPTS
+ let end = self.lastConsumedPTS ?? start
+ let now = ProcessInfo.processInfo.systemUptime
+ let gap = self.diagLastEouUptime.map { now - $0 }
+ self.diagLastEouUptime = now
+ self.utteranceStartPTS = nil
+ await self.manager.reset()
+ let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !trimmed.isEmpty else { return }
+ guard let start, let end else {
+ self.diag("EOU fired but no start PTS — dropped (chars=\(text.count))")
+ return
+ }
+ self.lastUtteranceEndPTS = end
+ self.diagUtterances += 1
+ self.diag(String(
+ format: "EOU #%d span=[%.2f–%.2f] (%.1fs) sinceLastEOU=%@ text=%@",
+ self.diagUtterances, start.seconds, end.seconds, end.seconds - start.seconds,
+ gap.map { String(format: "%.1fs", $0) } ?? "first",
+ trimmed
+ ))
+ self.onUtterance?(self.kind, trimmed, start, end)
+ }
+
+ /// A saturated queue sheds many samples in a burst. Recording one pending resync instead of
+ /// resetting per sample keeps a 250-sample burst from issuing 250 decoder resets and 250
+ /// degraded notifications; the drain loop performs exactly one resync before it next consumes.
+ private func noteDrop() {
+ self.diagDrops += 1
+ self.pendingResync = true
+ }
+
+ private func applyPendingResyncIfNeeded() async {
+ guard self.pendingResync else { return }
+ self.pendingResync = false
+ self.diag("queue saturated — resyncing after \(self.diagDrops) dropped samples")
+ await self.resetUtterance()
+ self.onDegraded?(self.kind, "Live captions dropped audio and resynced.")
+ }
+
+ private func resetUtterance() async {
+ self.utteranceStartPTS = nil
+ self.lastConsumedPTS = nil
+ await self.manager.reset()
+ }
+
+ /// Persistent converter reused across calls; FluidAudio's own `appendAudio` takes a fast path
+ /// once the buffer already matches its 16kHz mono target, so this is the only resample per chunk.
+ private func convert(_ buffer: AVAudioPCMBuffer) -> AVAudioPCMBuffer? {
+ let format = buffer.format
+ if format.sampleRate == self.targetFormat.sampleRate,
+ format.channelCount == self.targetFormat.channelCount,
+ format.commonFormat == self.targetFormat.commonFormat
+ {
+ return buffer
+ }
+ if self.converter == nil || self.converterSourceFormat != format {
+ self.converterSourceFormat = format
+ self.converter = AVAudioConverter(from: format, to: self.targetFormat)
+ }
+ guard let converter = self.converter else { return nil }
+
+ let ratio = self.targetFormat.sampleRate / format.sampleRate
+ let capacity = AVAudioFrameCount((Double(buffer.frameLength) * ratio).rounded(.up)) + 16
+ guard let output = AVAudioPCMBuffer(pcmFormat: self.targetFormat, frameCapacity: capacity) else { return nil }
+
+ let provided = OSAllocatedUnfairLock(initialState: false)
+ var error: NSError?
+ let status = converter.convert(to: output, error: &error) { _, inputStatus in
+ let wasProvided = provided.withLock { state -> Bool in
+ if state { return true }
+ state = true
+ return false
+ }
+ if wasProvided {
+ inputStatus.pointee = .noDataNow
+ return nil
+ }
+ inputStatus.pointee = .haveData
+ return buffer
+ }
+ guard status != .error else { return nil }
+ return output
+ }
+}
+#endif
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift
new file mode 100644
index 00000000..0f1c5f27
--- /dev/null
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift
@@ -0,0 +1,204 @@
+import AVFoundation
+import CoreMedia
+import Foundation
+
+/// Owns the two live-transcription engines for one meeting recording and publishes a snapshot for
+/// the UI. Entirely additive to the recording path: `offer(kind:sampleBuffer:)` is the only entry
+/// point invoked from the capture tee, and it never blocks or throws into the capture callback.
+///
+/// Not `@MainActor` on purpose — `offer` must be callable synchronously from the SCStream callback
+/// thread. `onUpdate` is responsible for hopping to the main actor if the caller needs that.
+final nonisolated class MeetingLiveTranscriptionCoordinator: @unchecked Sendable {
+ /// Two `StreamingEouAsrManager` instances measured at ~470MB RSS each. Below this, skip live
+ /// entirely rather than risk contending with the recording or the later batch model.
+ static let minimumPhysicalMemoryBytes: UInt64 = 8 * 1_024 * 1_024 * 1_024
+ static let echoWindowSeconds: TimeInterval = 20
+
+ static func isMemorySufficient(physicalMemory: UInt64) -> Bool {
+ physicalMemory >= Self.minimumPhysicalMemoryBytes
+ }
+
+ private let stateLock = NSLock()
+ private var snapshot: MeetingLiveTranscriptSnapshot = .empty
+ private var recentThemUtterances: [MeetingLiveUtterance] = []
+ private var offerCounts: [MeetingAudioTrackKind: Int] = [:]
+ private let originBox = MeetingLiveOriginBox()
+ private let onUpdate: @Sendable (MeetingLiveTranscriptSnapshot) -> Void
+
+ #if arch(arm64)
+ private var microphoneEngine: MeetingLiveTrackEngine?
+ private var applicationEngine: MeetingLiveTrackEngine?
+ #endif
+
+ init(onUpdate: @escaping @Sendable (MeetingLiveTranscriptSnapshot) -> Void) {
+ self.onUpdate = onUpdate
+ }
+
+ func start(mode: MeetingCaptureMode) {
+ #if arch(arm64)
+ guard Self.isMemorySufficient(physicalMemory: ProcessInfo.processInfo.physicalMemory) else {
+ DebugLogger.shared.info(
+ "Live meeting transcription skipped: below memory threshold.",
+ source: "MeetingLiveTranscriptionCoordinator"
+ )
+ self.publish { $0.settingAvailability(.unavailable(reason: "Not enough memory available for live captions.")) }
+ return
+ }
+
+ DebugLogger.shared.info(
+ "[live] starting engines mode=\(mode) physicalMemory=\(ProcessInfo.processInfo.physicalMemory / 1_073_741_824)GB",
+ source: "MeetingLive"
+ )
+ let microphone = MeetingLiveTrackEngine(kind: .microphone)
+ self.stateLock.withLock { self.microphoneEngine = microphone }
+ self.launch(microphone)
+
+ if mode == .onlineCall {
+ let application = MeetingLiveTrackEngine(kind: .applicationAudio)
+ self.stateLock.withLock { self.applicationEngine = application }
+ self.launch(application)
+ }
+ self.publish { $0.settingAvailability(.unavailable(reason: "Live captions are loading…")) }
+ #else
+ self.publish { $0.settingAvailability(.unavailable(reason: "Live captions require Apple Silicon.")) }
+ #endif
+ }
+
+ /// The capture-tee entry point. Copies the sample immediately, then hands it to the matching
+ /// track's bounded queue — never retains the `CMSampleBuffer` beyond this call.
+ func offer(kind: MeetingAudioTrackKind, sampleBuffer: CMSampleBuffer) {
+ #if arch(arm64)
+ guard let sample = MeetingLiveSampleCopy.copy(sampleBuffer) else {
+ DebugLogger.shared.info("[live/tee] sample copy FAILED kind=\(kind)", source: "MeetingLive")
+ return
+ }
+ self.originBox.establish(sample.pts)
+ let engine: MeetingLiveTrackEngine? = self.stateLock.withLock { () -> MeetingLiveTrackEngine? in
+ let count = (self.offerCounts[kind] ?? 0) + 1
+ self.offerCounts[kind] = count
+ if count == 1 {
+ DebugLogger.shared.info(
+ "[live/tee] first sample kind=\(kind) pts=\(String(format: "%.3f", sample.pts.seconds)) sr=\(sample.buffer.format.sampleRate) ch=\(sample.buffer.format.channelCount)",
+ source: "MeetingLive"
+ )
+ }
+ let engine = kind == .microphone ? self.microphoneEngine : self.applicationEngine
+ if engine == nil, count == 1 {
+ DebugLogger.shared.info("[live/tee] no engine for kind=\(kind) — samples discarded", source: "MeetingLive")
+ }
+ return engine
+ }
+ engine?.offer(sample)
+ #endif
+ }
+
+ /// Must complete before the batch pipeline calls `ensureAsrReady()`, so both engines' CoreML
+ /// models are released before the offline model loads.
+ func stop() async {
+ #if arch(arm64)
+ let (microphone, application) = self.stateLock.withLock { () -> (MeetingLiveTrackEngine?, MeetingLiveTrackEngine?) in
+ defer {
+ self.microphoneEngine = nil
+ self.applicationEngine = nil
+ }
+ return (self.microphoneEngine, self.applicationEngine)
+ }
+ DebugLogger.shared.info(
+ "[live] stopping engines offers=\(self.offerCounts.map { "\($0.key)=\($0.value)" }.sorted().joined(separator: " "))",
+ source: "MeetingLive"
+ )
+ await microphone?.stop()
+ await application?.stop()
+ DebugLogger.shared.info("[live] engines stopped, models released", source: "MeetingLive")
+ #endif
+ }
+
+ #if arch(arm64)
+ private func launch(_ engine: MeetingLiveTrackEngine) {
+ Task { [weak self] in
+ guard let self else { return }
+ await engine.configure(
+ onPartial: { [weak self] kind, text, start, end in
+ self?.handlePartial(kind: kind, text: text, start: start, end: end)
+ },
+ onUtterance: { [weak self] kind, text, start, end in
+ self?.handleUtterance(kind: kind, text: text, start: start, end: end)
+ },
+ onDegraded: { [weak self] kind, reason in
+ self?.handleDegraded(kind: kind, reason: reason)
+ },
+ onReady: { [weak self] kind in
+ self?.handleReady(kind: kind)
+ }
+ )
+ await engine.start()
+ }
+ }
+
+ private func handlePartial(kind: MeetingAudioTrackKind, text: String, start: CMTime, end: CMTime) {
+ let speaker = Self.speaker(for: kind)
+ self.publish { $0.settingPartial(text, for: speaker) }
+ }
+
+ private func handleUtterance(kind: MeetingAudioTrackKind, text: String, start: CMTime, end: CMTime) {
+ guard let origin = self.originBox.current else { return }
+ let startSeconds = MeetingLiveTimeConversion.sessionSeconds(pts: start, origin: origin)
+ let endSeconds = MeetingLiveTimeConversion.sessionSeconds(pts: end, origin: origin)
+ let speaker = Self.speaker(for: kind)
+
+ let updated: MeetingLiveTranscriptSnapshot = self.stateLock.withLock {
+ if speaker == .you {
+ let recentThem = MeetingLiveEchoFilter.recentThemText(
+ from: self.recentThemUtterances,
+ before: startSeconds,
+ windowSeconds: Self.echoWindowSeconds
+ )
+ if MeetingLiveEchoFilter.shouldSuppress(micText: text, recentThemText: recentThem) {
+ DebugLogger.shared.info(
+ "[live/ECHO] SUPPRESSED mic utterance [\(String(format: "%.2f", startSeconds))] text=\(text)",
+ source: "MeetingLive"
+ )
+ self.snapshot = self.snapshot.settingPartial(nil, for: .you)
+ return self.snapshot
+ }
+ DebugLogger.shared.info(
+ "[live/ECHO] kept mic utterance [\(String(format: "%.2f", startSeconds))] text=\(text)",
+ source: "MeetingLive"
+ )
+ } else {
+ let record = MeetingLiveUtterance(id: UUID(), speaker: .them, text: text, start: startSeconds, end: endSeconds)
+ self.recentThemUtterances.append(record)
+ self.recentThemUtterances.removeAll { $0.end < startSeconds - Self.echoWindowSeconds }
+ }
+ let utterance = MeetingLiveUtterance(id: UUID(), speaker: speaker, text: text, start: startSeconds, end: endSeconds)
+ self.snapshot = self.snapshot.inserting(utterance).settingPartial(nil, for: speaker)
+ return self.snapshot
+ }
+ self.onUpdate(updated)
+ }
+
+ private func handleDegraded(kind: MeetingAudioTrackKind, reason: String) {
+ DebugLogger.shared.info("[live] DEGRADED kind=\(kind) reason=\(reason)", source: "MeetingLive")
+ self.publish { $0.settingAvailability(.degraded(reason: reason)) }
+ }
+
+ private func handleReady(kind: MeetingAudioTrackKind) {
+ self.publish { snapshot in
+ guard case .unavailable = snapshot.availability else { return snapshot }
+ return snapshot.settingAvailability(.available)
+ }
+ }
+
+ private static func speaker(for kind: MeetingAudioTrackKind) -> MeetingLiveSpeaker {
+ kind == .microphone ? .you : .them
+ }
+ #endif
+
+ private func publish(_ transform: (MeetingLiveTranscriptSnapshot) -> MeetingLiveTranscriptSnapshot) {
+ let updated: MeetingLiveTranscriptSnapshot = self.stateLock.withLock {
+ self.snapshot = transform(self.snapshot)
+ return self.snapshot
+ }
+ self.onUpdate(updated)
+ }
+}
diff --git a/Sources/Fluid/Services/Meeting/MeetingCaptureEngine.swift b/Sources/Fluid/Services/Meeting/MeetingCaptureEngine.swift
index 57f77dfd..fa5f0fe0 100644
--- a/Sources/Fluid/Services/Meeting/MeetingCaptureEngine.swift
+++ b/Sources/Fluid/Services/Meeting/MeetingCaptureEngine.swift
@@ -10,7 +10,8 @@ nonisolated protocol MeetingCaptureControlling: Sendable {
session: MeetingSession,
configuration: MeetingCaptureConfiguration,
sessionDirectory: URL,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
) async throws -> MeetingCaptureStartResult
func stop(sessionID: MeetingSessionID) async throws -> MeetingCaptureStopResult
@@ -34,7 +35,8 @@ actor MeetingCaptureEngine: MeetingCaptureControlling {
session: MeetingSession,
configuration: MeetingCaptureConfiguration,
sessionDirectory: URL,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)? = nil
) async throws -> MeetingCaptureStartResult {
try configuration.validate()
guard self.activeCapture == nil, self.startingSessionID == nil, self.stopTask == nil else {
@@ -68,7 +70,8 @@ actor MeetingCaptureEngine: MeetingCaptureControlling {
microphone: configuration.microphone,
applicationWriter: applicationWriter,
microphoneWriter: microphoneWriter,
- eventHandler: eventHandler
+ eventHandler: eventHandler,
+ liveAudioHandler: liveAudioHandler
)
case .inRoom:
guard let microphoneWriter = writersByKind[.microphone] else {
@@ -77,7 +80,8 @@ actor MeetingCaptureEngine: MeetingCaptureControlling {
runtime = try InRoomMicrophoneCaptureRuntime(
microphone: configuration.microphone,
writer: microphoneWriter,
- eventHandler: eventHandler
+ eventHandler: eventHandler,
+ liveAudioHandler: liveAudioHandler
)
}
@@ -307,6 +311,7 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
private let applicationWriter: MeetingAudioChunkWriter
private let microphoneWriter: MeetingAudioChunkWriter
private let eventHandler: @Sendable (MeetingCaptureEvent) -> Void
+ private let liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
private let stateLock = NSLock()
private var stream: SCStream
private var scope: MeetingCaptureScope
@@ -327,7 +332,8 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
microphone: MeetingMicrophoneIdentity,
applicationWriter: MeetingAudioChunkWriter,
microphoneWriter: MeetingAudioChunkWriter,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
) {
self.stream = stream
self.scope = scope
@@ -336,6 +342,7 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
self.applicationWriter = applicationWriter
self.microphoneWriter = microphoneWriter
self.eventHandler = eventHandler
+ self.liveAudioHandler = liveAudioHandler
super.init()
}
@@ -344,7 +351,8 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
microphone: MeetingMicrophoneIdentity,
applicationWriter: MeetingAudioChunkWriter,
microphoneWriter: MeetingAudioChunkWriter,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
) async throws -> ScreenCaptureMeetingRuntime {
let built = try await Self.buildStream(application: application, microphone: microphone)
let runtime = ScreenCaptureMeetingRuntime(
@@ -354,7 +362,8 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
microphone: microphone,
applicationWriter: applicationWriter,
microphoneWriter: microphoneWriter,
- eventHandler: eventHandler
+ eventHandler: eventHandler,
+ liveAudioHandler: liveAudioHandler
)
built.delegateProxy.owner = runtime
runtime.delegateProxy = built.delegateProxy
@@ -504,8 +513,10 @@ private final nonisolated class ScreenCaptureMeetingRuntime: NSObject, MeetingCa
switch outputType {
case .audio:
self.applicationWriter.enqueue(sampleBuffer)
+ self.liveAudioHandler?(.applicationAudio, sampleBuffer)
case .microphone:
self.microphoneWriter.enqueue(sampleBuffer)
+ self.liveAudioHandler?(.microphone, sampleBuffer)
case .screen:
break
@unknown default:
@@ -621,6 +632,7 @@ private final nonisolated class InRoomMicrophoneCaptureRuntime: NSObject, Meetin
private let controlQueue = DispatchQueue(label: "com.fluidvoice.meeting.inroom.control")
private let stateLock = NSLock()
private let eventHandler: @Sendable (MeetingCaptureEvent) -> Void
+ private let liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
private var stopping = false
private var emittedUnexpectedStop = false
private var notificationObservers: [NSObjectProtocol] = []
@@ -628,10 +640,12 @@ private final nonisolated class InRoomMicrophoneCaptureRuntime: NSObject, Meetin
init(
microphone: MeetingMicrophoneIdentity,
writer: MeetingAudioChunkWriter,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
) throws {
self.writer = writer
self.eventHandler = eventHandler
+ self.liveAudioHandler = liveAudioHandler
super.init()
guard let device = AVCaptureDevice(uniqueID: microphone.captureDeviceID) else {
throw MeetingCaptureError.microphoneUnavailable
@@ -694,6 +708,7 @@ private final nonisolated class InRoomMicrophoneCaptureRuntime: NSObject, Meetin
self.stateLock.unlock()
guard shouldAccept else { return }
self.writer.enqueue(sampleBuffer)
+ self.liveAudioHandler?(.microphone, sampleBuffer)
}
private func observeSessionLifecycle() {
diff --git a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
index 02035da2..491a72c6 100644
--- a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
+++ b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
@@ -73,6 +73,7 @@ final class MeetingSessionCoordinator: ObservableObject {
@Published private(set) var activeSession: MeetingSession?
@Published private(set) var latestCompletedSession: MeetingSession?
@Published private(set) var trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth] = [:]
+ @Published private(set) var liveTranscript: MeetingLiveTranscriptSnapshot = .empty
/// Sustained application-audio silence, in seconds, before the silence watchdog degrades the session.
private static let silenceWatchdogThresholdSeconds: TimeInterval = 90
@@ -90,6 +91,7 @@ final class MeetingSessionCoordinator: ObservableObject {
private var degradeReason: DegradeReason?
private var activityLease: MeetingAudioActivityLease?
+ private var liveTranscriptionCoordinator: MeetingLiveTranscriptionCoordinator?
private var captureGeneration: UUID?
private var operationGeneration: UUID?
private var stopTask: Task<MeetingSession, Error>? {
@@ -117,6 +119,7 @@ final class MeetingSessionCoordinator: ObservableObject {
case reassign(segmentID: MeetingTranscriptSegmentID, previousSpeakerID: SessionSpeakerID?, previousRevision: Int)
case merge(sourceID: SessionSpeakerID, targetID: SessionSpeakerID,
movedSegments: [(id: MeetingTranscriptSegmentID, previousRevision: Int)])
+ case renameBatch([(speakerID: SessionSpeakerID, previousName: String)])
}
private var correctionUndoStacks: [MeetingSessionID: [TranscriptCorrection]] = [:]
private static let correctionUndoStackCap = 50
@@ -244,6 +247,15 @@ final class MeetingSessionCoordinator: ObservableObject {
var captureStarted = false
var captureStartAttempted = false
+ let liveTranscriptionCoordinator = MeetingLiveTranscriptionCoordinator { [weak self] snapshot in
+ Task { @MainActor [weak self] in
+ self?.liveTranscript = snapshot
+ }
+ }
+ self.liveTranscriptionCoordinator = liveTranscriptionCoordinator
+ self.liveTranscript = .empty
+ liveTranscriptionCoordinator.start(mode: configuration.mode)
+
do {
try await self.store.create(session)
let sessionDirectory = try await self.store.sessionDirectory(for: session.id)
@@ -251,12 +263,16 @@ final class MeetingSessionCoordinator: ObservableObject {
let startResult = try await self.capture.start(
session: session,
configuration: configuration,
- sessionDirectory: sessionDirectory
- ) { [weak self] event in
- Task { @MainActor [weak self] in
- self?.handleCaptureEvent(event, generation: generation)
+ sessionDirectory: sessionDirectory,
+ eventHandler: { [weak self] event in
+ Task { @MainActor [weak self] in
+ self?.handleCaptureEvent(event, generation: generation)
+ }
+ },
+ liveAudioHandler: { [weak liveTranscriptionCoordinator] kind, sampleBuffer in
+ liveTranscriptionCoordinator?.offer(kind: kind, sampleBuffer: sampleBuffer)
}
- }
+ )
captureStarted = true
guard self.operationGeneration == generation, !Task.isCancelled else {
throw CancellationError()
@@ -274,6 +290,7 @@ final class MeetingSessionCoordinator: ObservableObject {
Task { @MainActor [weak self] in await self?.sweepExpiredAudio() }
return session
} catch {
+ await self.tearDownLiveTranscription()
if self.operationGeneration != generation {
if captureStarted {
_ = try? await self.capture.stop(sessionID: session.id)
@@ -616,6 +633,22 @@ final class MeetingSessionCoordinator: ObservableObject {
}
}
+ @discardableResult
+ func renameSpeakers(sessionID: MeetingSessionID, names: [SessionSpeakerID: String]) async throws -> MeetingSession {
+ try await self.performCorrection(sessionID: sessionID) { session in
+ var applied: [(speakerID: SessionSpeakerID, previousName: String)] = []
+ for (speakerID, name) in names {
+ guard let existing = session.speakers.first(where: { $0.id == speakerID }),
+ existing.mergedIntoSpeakerID == nil else { continue }
+ let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !trimmed.isEmpty, trimmed != existing.displayName else { continue }
+ try session.renameSpeaker(id: speakerID, to: trimmed)
+ applied.append((speakerID, existing.displayName))
+ }
+ return .renameBatch(applied)
+ }
+ }
+
@discardableResult
func reassignSegment(
sessionID: MeetingSessionID,
@@ -892,6 +925,14 @@ final class MeetingSessionCoordinator: ObservableObject {
session.transcriptSegments[segmentIndex].revision = previousRevision
}
return true
+ case let .renameBatch(entries):
+ var restored = false
+ for entry in entries {
+ guard let index = session.speakers.firstIndex(where: { $0.id == entry.speakerID }) else { continue }
+ session.speakers[index].displayName = entry.previousName
+ restored = true
+ }
+ return restored
}
}
@@ -1049,6 +1090,7 @@ final class MeetingSessionCoordinator: ObservableObject {
guard var session = self.activeSession else {
await self.flushQueuedPersistence()
await self.capture.shutdownForTermination()
+ await self.tearDownLiveTranscription()
self.releaseActivityLease()
return
}
@@ -1071,6 +1113,7 @@ final class MeetingSessionCoordinator: ObservableObject {
} else {
await self.capture.shutdownForTermination()
}
+ await self.tearDownLiveTranscription()
session.state = .interrupted
if !session.events.contains(where: { $0.kind == .appTermination }) {
@@ -1123,6 +1166,7 @@ final class MeetingSessionCoordinator: ObservableObject {
await self.handleStopFailure(error, session: session, generation: generation)
throw error
}
+ await self.tearDownLiveTranscription()
guard self.operationGeneration == generation, !Task.isCancelled else {
throw CancellationError()
}
@@ -1340,6 +1384,7 @@ final class MeetingSessionCoordinator: ObservableObject {
}
session.failures.append(Self.failure(from: error, domain: .capture, recoverable: true))
}
+ await self.tearDownLiveTranscription()
guard self.terminationTask == nil, !Task.isCancelled else { return }
session.state = .interrupted
@@ -1372,6 +1417,7 @@ final class MeetingSessionCoordinator: ObservableObject {
await self.capture.shutdownForTermination()
session.endedAt = session.endedAt ?? Date()
}
+ await self.tearDownLiveTranscription()
let failure = Self.failure(from: error, domain: .capture, recoverable: true)
session.failures.append(failure)
session.events.append(MeetingSessionEvent(
@@ -1415,6 +1461,15 @@ final class MeetingSessionCoordinator: ObservableObject {
}
}
+ /// Must complete before any code path that calls into `processing.process`, so both live
+ /// engines' CoreML models are released before the batch pipeline's `ensureAsrReady()` loads.
+ private func tearDownLiveTranscription() async {
+ guard let coordinator = self.liveTranscriptionCoordinator else { return }
+ self.liveTranscriptionCoordinator = nil
+ await coordinator.stop()
+ self.liveTranscript = .empty
+ }
+
private func releaseActivityLease() {
guard let lease = self.activityLease else { return }
self.audioArbiter.release(lease)
diff --git a/Sources/Fluid/UI/MeetingAssignSpeakersSheet.swift b/Sources/Fluid/UI/MeetingAssignSpeakersSheet.swift
new file mode 100644
index 00000000..ab6dc9b4
--- /dev/null
+++ b/Sources/Fluid/UI/MeetingAssignSpeakersSheet.swift
@@ -0,0 +1,234 @@
+import SwiftUI
+
+/// Sample-quote extraction, kept separate from the view so it stays trivially testable.
+nonisolated enum MeetingAssignSpeakersQuoteSource {
+ private static let maxQuoteLength = 180
+
+ /// First two things a speaker actually said: final, non-echo, in time order.
+ static func sampleQuotes(for speakerID: SessionSpeakerID, in segments: [MeetingTranscriptSegment]) -> [String] {
+ segments
+ .filter { $0.speakerID == speakerID && !$0.isEcho && $0.status == .final }
+ .sorted { $0.start.seconds < $1.start.seconds }
+ .compactMap { segment -> String? in
+ let trimmed = segment.text.trimmingCharacters(in: .whitespacesAndNewlines)
+ return trimmed.isEmpty ? nil : Self.truncated(trimmed)
+ }
+ .prefix(2)
+ .map { $0 }
+ }
+
+ private static func truncated(_ text: String) -> String {
+ guard text.count > Self.maxQuoteLength else { return text }
+ let cutoff = text.index(text.startIndex, offsetBy: Self.maxQuoteLength)
+ let prefix = text[text.startIndex..<cutoff]
+ if let lastSpace = prefix.lastIndex(of: " ") {
+ return "\(text[text.startIndex..<lastSpace])…"
+ }
+ return "\(prefix)…"
+ }
+}
+
+nonisolated enum MeetingAssignSpeakersValidation {
+ /// Only a collision the user just created blocks the save. Two speakers can already share a
+ /// name — the pipeline emits a bare "Speaker" for re-matched clusters — and that transcript
+ /// must stay nameable rather than deadlocking on a duplicate nobody typed.
+ static func duplicateName(
+ current: [(id: SessionSpeakerID, displayName: String)],
+ drafts: [SessionSpeakerID: String]
+ ) -> String? {
+ let resulting = current.map { speaker -> (name: String, changed: Bool) in
+ let typed = (drafts[speaker.id] ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
+ let name = typed.isEmpty ? speaker.displayName : typed
+ return (name, name != speaker.displayName)
+ }
+ for index in resulting.indices {
+ for other in resulting[(index + 1)...]
+ where other.name.caseInsensitiveCompare(resulting[index].name) == .orderedSame {
+ guard resulting[index].changed || other.changed else { continue }
+ return other.name
+ }
+ }
+ return nil
+ }
+}
+
+struct MeetingAssignSpeakersSheet: View {
+ let speakers: [MeetingSessionSpeaker]
+ let quotesBySpeaker: [SessionSpeakerID: [String]]
+ let tints: [SessionSpeakerID: Color]
+ let accentColor: Color
+ let focusedSpeakerID: SessionSpeakerID?
+ let onSave: ([SessionSpeakerID: String]) async -> String?
+ let onCancel: () -> Void
+
+ @Environment(\.theme) private var theme
+ @State private var drafts: [SessionSpeakerID: String]
+ @State private var isSaving = false
+ @State private var errorMessage: String?
+ @FocusState private var focusedField: SessionSpeakerID?
+
+ init(
+ speakers: [MeetingSessionSpeaker],
+ quotesBySpeaker: [SessionSpeakerID: [String]],
+ tints: [SessionSpeakerID: Color],
+ accentColor: Color,
+ focusedSpeakerID: SessionSpeakerID? = nil,
+ onSave: @escaping ([SessionSpeakerID: String]) async -> String?,
+ onCancel: @escaping () -> Void
+ ) {
+ self.speakers = speakers
+ self.quotesBySpeaker = quotesBySpeaker
+ self.tints = tints
+ self.accentColor = accentColor
+ self.focusedSpeakerID = focusedSpeakerID
+ self.onSave = onSave
+ self.onCancel = onCancel
+ self._drafts = State(initialValue: Dictionary(uniqueKeysWithValues: speakers.map { ($0.id, $0.displayName) }))
+ }
+
+ var body: some View {
+ VStack(spacing: 0) {
+ self.header
+
+ Divider()
+
+ ScrollViewReader { proxy in
+ ScrollView {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xl) {
+ ForEach(self.speakers) { speaker in
+ self.row(for: speaker).id(speaker.id)
+ }
+ }
+ .padding(self.theme.metrics.spacing.xl)
+ }
+ .onAppear {
+ guard let focusedSpeakerID = self.focusedSpeakerID else { return }
+ proxy.scrollTo(focusedSpeakerID, anchor: .center)
+ self.focusedField = focusedSpeakerID
+ }
+ }
+
+ if let errorMessage {
+ Divider()
+ Label(errorMessage, systemImage: "exclamationmark.circle")
+ .font(self.theme.typography.caption)
+ .foregroundStyle(self.theme.palette.warning)
+ .padding(.horizontal, self.theme.metrics.spacing.xl)
+ .padding(.vertical, self.theme.metrics.spacing.sm)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+
+ Divider()
+
+ HStack(spacing: self.theme.metrics.spacing.md) {
+ Spacer()
+ Button("Cancel", action: self.onCancel)
+ .fluidButton(.compact, size: .medium)
+ .keyboardShortcut(.cancelAction)
+ .disabled(self.isSaving)
+ Button("Save names") { Task { await self.save() } }
+ .fluidButton(.accent, size: .medium)
+ .keyboardShortcut(.defaultAction)
+ .disabled(self.isSaving)
+ }
+ .padding(self.theme.metrics.spacing.lg)
+ }
+ .frame(minWidth: 480, idealWidth: 560, maxWidth: 560)
+ .frame(minHeight: 420, idealHeight: 560)
+ .background(self.theme.palette.windowBackground)
+ }
+
+ private var header: some View {
+ HStack(alignment: .top, spacing: self.theme.metrics.spacing.md) {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {
+ Text("Assign speakers")
+ .font(self.theme.typography.title)
+ Text("Name each voice and we'll relabel the whole transcript.")
+ .font(self.theme.typography.bodySmall)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ }
+ Spacer()
+ Button("Close", systemImage: "xmark") { self.onCancel() }
+ .labelStyle(.iconOnly)
+ .buttonStyle(.borderless)
+ .accessibilityLabel("Close")
+ }
+ .padding(.horizontal, self.theme.metrics.spacing.xl)
+ .padding(.vertical, self.theme.metrics.spacing.lg)
+ }
+
+ @ViewBuilder
+ private func row(for speaker: MeetingSessionSpeaker) -> some View {
+ let tint = speaker.isLocalUser ? self.accentColor : (self.tints[speaker.id] ?? self.theme.palette.tertiaryText)
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.sm) {
+ HStack(spacing: self.theme.metrics.spacing.sm) {
+ Circle()
+ .fill(tint)
+ .frame(width: 10, height: 10)
+ Text(speaker.displayName)
+ .font(self.theme.typography.captionSmall)
+ .tracking(1.1)
+ .textCase(.uppercase)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ }
+
+ let quotes = self.quotesBySpeaker[speaker.id] ?? []
+ if quotes.isEmpty {
+ Text("No sample audio")
+ .font(self.theme.typography.bodySmall)
+ .foregroundStyle(self.theme.palette.tertiaryText)
+ .padding(.leading, self.theme.metrics.spacing.md)
+ .overlay(alignment: .leading) {
+ Rectangle().fill(tint.opacity(0.35)).frame(width: 2)
+ }
+ } else {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {
+ ForEach(Array(quotes.enumerated()), id: \.offset) { _, quote in
+ Text(quote)
+ .font(self.theme.typography.bodySmall)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ .padding(.leading, self.theme.metrics.spacing.md)
+ .overlay(alignment: .leading) {
+ Rectangle().fill(tint.opacity(0.35)).frame(width: 2)
+ }
+ }
+ }
+ }
+
+ TextField(
+ speaker.displayName,
+ text: Binding(
+ get: { self.drafts[speaker.id] ?? speaker.displayName },
+ set: { self.drafts[speaker.id] = $0 }
+ ),
+ prompt: Text(speaker.displayName)
+ )
+ .textFieldStyle(.roundedBorder)
+ .focused(self.$focusedField, equals: speaker.id)
+ .disabled(self.isSaving)
+ }
+ }
+
+ private func save() async {
+ self.errorMessage = nil
+
+ if let duplicate = MeetingAssignSpeakersValidation.duplicateName(
+ current: self.speakers.map { (id: $0.id, displayName: $0.displayName) },
+ drafts: self.drafts
+ ) {
+ self.errorMessage = "Two speakers are both named \"\(duplicate)\". Give them different names, or merge them from the transcript."
+ return
+ }
+
+ self.isSaving = true
+ let message = await self.onSave(self.drafts)
+ self.isSaving = false
+
+ if let message {
+ self.errorMessage = message
+ } else {
+ // No separate "dismiss" callback: onCancel is just "close the sheet" either way.
+ self.onCancel()
+ }
+ }
+}
diff --git a/Sources/Fluid/UI/MeetingSpeakerPalette.swift b/Sources/Fluid/UI/MeetingSpeakerPalette.swift
new file mode 100644
index 00000000..f117f845
--- /dev/null
+++ b/Sources/Fluid/UI/MeetingSpeakerPalette.swift
@@ -0,0 +1,57 @@
+import AppKit
+import SwiftUI
+
+/// Stable per-speaker tints for the transcript. Colour is decoration on top of the name, never
+/// the only way to tell speakers apart, so it stays quiet enough to read a whole meeting in.
+nonisolated enum MeetingSpeakerPalette {
+ /// Muted in light (pastels wash out on white), lifted in dark. Ordered so neighbouring
+ /// speakers stay distinguishable to the common forms of colour blindness.
+ private static let tints: [(light: (Int, Int, Int), dark: (Int, Int, Int))] = [
+ (light: (0x33, 0x55, 0x86), dark: (0x84, 0xA9, 0xDA)),
+ (light: (0x4C, 0x6C, 0x3D), dark: (0x93, 0xBB, 0x82)),
+ (light: (0x8C, 0x4C, 0x33), dark: (0xDB, 0x93, 0x74)),
+ (light: (0x5F, 0x42, 0x7C), dark: (0xAE, 0x92, 0xD2)),
+ (light: (0x77, 0x5B, 0x18), dark: (0xC9, 0xAD, 0x55)),
+ (light: (0x27, 0x62, 0x63), dark: (0x72, 0xB3, 0xB4)),
+ ]
+
+ static func rgb(forSpeakerIndex index: Int, isDark: Bool) -> (red: Int, green: Int, blue: Int) {
+ let slot = ((index % self.tints.count) + self.tints.count) % self.tints.count
+ let entry = self.tints[slot]
+ let value = isDark ? entry.dark : entry.light
+ return (value.0, value.1, value.2)
+ }
+
+ static func tint(forSpeakerIndex index: Int) -> Color {
+ Color(nsColor: NSColor(name: nil) { appearance in
+ let isDark = appearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua
+ let value = Self.rgb(forSpeakerIndex: index, isDark: isDark)
+ return NSColor(
+ srgbRed: CGFloat(value.red) / 255,
+ green: CGFloat(value.green) / 255,
+ blue: CGFloat(value.blue) / 255,
+ alpha: 1
+ )
+ })
+ }
+
+ /// The unnamed catch-all bucket for mic audio that isn't confidently the local user.
+ static let unknownMicrophoneSpeakerName = "Microphone / Unknown"
+
+ /// Index allocated by position so renaming one speaker never recolours the others.
+ /// The unnamed catch-all gets an index but no tint — it is a bucket, not a person.
+ static func tintIndices(for speakers: [MeetingSessionSpeaker]) -> [SessionSpeakerID: Int] {
+ var indices: [SessionSpeakerID: Int] = [:]
+ var next = 0
+ for speaker in speakers where !speaker.isLocalUser {
+ defer { next += 1 }
+ guard speaker.displayName != Self.unknownMicrophoneSpeakerName else { continue }
+ indices[speaker.id] = next
+ }
+ return indices
+ }
+
+ static func tints(for speakers: [MeetingSessionSpeaker]) -> [SessionSpeakerID: Color] {
+ Self.tintIndices(for: speakers).mapValues { Self.tint(forSpeakerIndex: $0) }
+ }
+}
diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swift
index fa8e9956..05ff5e25 100644
--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift
+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift
@@ -169,6 +169,7 @@ struct MeetingTranscriptionView: View {
onMergeSpeakers: self.mergeSpeakers,
onUndoCorrection: self.undoTranscriptCorrection,
onRenameSession: self.renameMeetingSession,
+ onAssignSpeakers: self.assignSpeakers,
canUndoCorrection: { self.coordinator.canUndoCorrection(sessionID: $0) },
isQuiescent: self.coordinator.isQuiescent,
onOpenMeetingSettings: self.openMeetingSettings,
@@ -308,14 +309,14 @@ struct MeetingTranscriptionView: View {
return .failed(session: nil, message: "The active meeting could not be loaded.")
}
if self.isStopping {
- return .stopping(session: session, trackHealth: self.coordinator.trackHealth)
+ return .stopping(session: session, trackHealth: self.coordinator.trackHealth, liveTranscript: self.coordinator.liveTranscript)
}
- return .recording(session: session, trackHealth: self.coordinator.trackHealth)
+ return .recording(session: session, trackHealth: self.coordinator.trackHealth, liveTranscript: self.coordinator.liveTranscript)
case .stopping:
guard let session = self.coordinator.activeSession else {
return .failed(session: nil, message: "The meeting is stopping, but its session could not be loaded.")
}
- return .stopping(session: session, trackHealth: self.coordinator.trackHealth)
+ return .stopping(session: session, trackHealth: self.coordinator.trackHealth, liveTranscript: self.coordinator.liveTranscript)
case let .processing(_, stage):
guard let session = self.coordinator.activeSession else {
return .failed(session: nil, message: "The meeting is processing, but its session could not be loaded.")
@@ -633,6 +634,18 @@ struct MeetingTranscriptionView: View {
}
}
+ private func assignSpeakers(sessionID: MeetingSessionID, names: [SessionSpeakerID: String]) async -> String? {
+ self.actionErrorMessage = nil
+ var errorMessage: String?
+ do {
+ _ = try await self.coordinator.renameSpeakers(sessionID: sessionID, names: names)
+ } catch {
+ errorMessage = error.localizedDescription
+ }
+ await self.loadMeetingHistory()
+ return errorMessage
+ }
+
private func mergeSpeakers(sessionID: MeetingSessionID, source: SessionSpeakerID, into targetID: SessionSpeakerID) {
self.actionErrorMessage = nil
Task {
@@ -1056,8 +1069,16 @@ enum MeetingTranscriptExportFormat {
enum MeetingTranscriptionCanvasState {
case setup(isStarting: Bool, recentSession: MeetingSession?)
- case recording(session: MeetingSession, trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth])
- case stopping(session: MeetingSession, trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth])
+ case recording(
+ session: MeetingSession,
+ trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth],
+ liveTranscript: MeetingLiveTranscriptSnapshot
+ )
+ case stopping(
+ session: MeetingSession,
+ trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth],
+ liveTranscript: MeetingLiveTranscriptSnapshot
+ )
case processing(session: MeetingSession, stage: MeetingProcessingStage)
case result(MeetingSession)
case failed(session: MeetingSession?, message: String)
@@ -1084,6 +1105,7 @@ struct MeetingTranscriptionCanvas: View {
let onMergeSpeakers: (MeetingSessionID, SessionSpeakerID, SessionSpeakerID) -> Void
let onUndoCorrection: (MeetingSessionID) -> Void
let onRenameSession: (MeetingSessionID, String) -> Void
+ let onAssignSpeakers: (MeetingSessionID, [SessionSpeakerID: String]) async -> String?
let canUndoCorrection: (MeetingSessionID) -> Bool
let isQuiescent: Bool
let onOpenMeetingSettings: () -> Void
@@ -1109,17 +1131,19 @@ struct MeetingTranscriptionCanvas: View {
onStart: self.onStart,
onOpenMeetingSettings: self.onOpenMeetingSettings
)
- case let .recording(session, trackHealth):
+ case let .recording(session, trackHealth, liveTranscript):
MeetingRecordingCanvas(
session: session,
trackHealth: trackHealth,
+ liveTranscript: liveTranscript,
isStopping: false,
onStop: self.onStop
)
- case let .stopping(session, trackHealth):
+ case let .stopping(session, trackHealth, liveTranscript):
MeetingRecordingCanvas(
session: session,
trackHealth: trackHealth,
+ liveTranscript: liveTranscript,
isStopping: true,
onStop: self.onStop
)
@@ -1143,6 +1167,7 @@ struct MeetingTranscriptionCanvas: View {
},
onUndo: { self.onUndoCorrection(session.id) },
onRenameSession: { title in self.onRenameSession(session.id, title) },
+ onAssignSpeakers: { names in await self.onAssignSpeakers(session.id, names) },
onClose: self.onCloseSelection
)
case let .failed(session, message):
@@ -1536,6 +1561,7 @@ private struct MeetingHistoryRow: View {
.buttonStyle(.plain)
.foregroundStyle(self.actionColor)
.disabled(!self.isQuiescent)
+ .accessibilityLabel(self.actionAccessibilityLabel ?? actionLabel)
}
}
.font(self.theme.typography.caption)
@@ -1575,6 +1601,15 @@ private struct MeetingHistoryRow: View {
}
private var actionLabel: String? {
+ switch self.session.state {
+ case .interrupted: return self.session.hasRetryableAudio ? "Retry" : nil
+ case .failed: return "Record again"
+ default: return nil
+ }
+ }
+
+ /// The row shows "Retry" to fit a narrow sidebar; spoken output keeps the full sentence.
+ private var actionAccessibilityLabel: String? {
switch self.session.state {
case .interrupted: return self.session.hasRetryableAudio ? "Retry transcription" : nil
case .failed: return "Record again"
@@ -2127,6 +2162,7 @@ private struct MeetingSetupCanvas: View {
private struct MeetingRecordingCanvas: View {
let session: MeetingSession
let trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth]
+ let liveTranscript: MeetingLiveTranscriptSnapshot
let isStopping: Bool
let onStop: () -> Void
@@ -2177,13 +2213,16 @@ private struct MeetingRecordingCanvas: View {
}
}
- Text(
- self.isStopping
- ? "Saving captured audio before offline transcription begins…"
- : "When the meeting ends, stop recording to transcribe it offline."
- )
- .font(self.theme.typography.body)
- .foregroundStyle(self.theme.palette.secondaryText)
+ if self.isStopping {
+ Text("Saving captured audio before offline transcription begins…")
+ .font(self.theme.typography.body)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ } else {
+ MeetingLiveTranscriptCard(snapshot: self.liveTranscript)
+ Text("When the meeting ends, stop recording to transcribe it offline.")
+ .font(self.theme.typography.caption)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ }
HStack {
Spacer()
@@ -2225,6 +2264,93 @@ private struct MeetingRecordingCanvas: View {
}
}
+/// Live captions during recording only — speaker identity is unresolved here (You/Them by track,
+/// not by diarization); the offline pipeline replaces this view's content entirely on completion.
+private struct MeetingLiveTranscriptCard: View {
+ let snapshot: MeetingLiveTranscriptSnapshot
+
+ @Environment(\.theme) private var theme
+
+ var body: some View {
+ ThemedCard(style: .subtle) {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.sm) {
+ HStack {
+ Text("Live captions")
+ .font(self.theme.typography.captionStrong)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ Spacer()
+ if let indicator = self.availabilityIndicator {
+ Label(indicator, systemImage: "exclamationmark.circle")
+ .font(self.theme.typography.caption)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ .labelStyle(.titleAndIcon)
+ }
+ }
+
+ if self.lines.isEmpty {
+ Text("Listening…")
+ .font(self.theme.typography.bodySmall)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ } else {
+ ScrollViewReader { proxy in
+ ScrollView {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {
+ ForEach(Array(self.lines.enumerated()), id: \.offset) { index, line in
+ self.lineView(line)
+ .id(index)
+ }
+ }
+ }
+ .frame(maxHeight: 160)
+ .onChange(of: self.lines.count) {
+ proxy.scrollTo(self.lines.count - 1, anchor: .bottom)
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private struct Line {
+ let speaker: MeetingLiveSpeaker
+ let text: String
+ let isPartial: Bool
+ }
+
+ /// Newest at the bottom; each engine's partial replaces in place rather than appending.
+ private var lines: [Line] {
+ var lines = self.snapshot.utterances.map { Line(speaker: $0.speaker, text: $0.text, isPartial: false) }
+ for speaker: MeetingLiveSpeaker in [.you, .them] {
+ if let partial = self.snapshot.partials[speaker], !partial.isEmpty {
+ lines.append(Line(speaker: speaker, text: partial, isPartial: true))
+ }
+ }
+ return lines
+ }
+
+ private var availabilityIndicator: String? {
+ switch self.snapshot.availability {
+ case .available:
+ return nil
+ case let .unavailable(reason), let .degraded(reason):
+ return reason
+ }
+ }
+
+ private func lineView(_ line: Line) -> some View {
+ HStack(alignment: .top, spacing: self.theme.metrics.spacing.xs) {
+ Text(line.speaker == .you ? "You" : "Them")
+ .font(self.theme.typography.captionStrong)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ .frame(width: 44, alignment: .leading)
+ Text(line.text)
+ .font(self.theme.typography.bodySmall)
+ .foregroundStyle(line.isPartial ? self.theme.palette.secondaryText : self.theme.palette.primaryText)
+ .italic(line.isPartial)
+ }
+ }
+}
+
private struct MeetingProcessingCanvas: View {
let session: MeetingSession
let stage: MeetingProcessingStage
@@ -2338,6 +2464,7 @@ private struct MeetingResultCanvas: View {
let onMergeSpeakers: (SessionSpeakerID, SessionSpeakerID) -> Void
let onUndo: () -> Void
let onRenameSession: (String) -> Void
+ let onAssignSpeakers: ([SessionSpeakerID: String]) async -> String?
let onClose: (() -> Void)?
@Environment(\.theme) private var theme
@@ -2345,11 +2472,28 @@ private struct MeetingResultCanvas: View {
@State private var pendingRenameText = ""
@State private var isRenamingSession = false
@State private var pendingRenameSessionText = ""
+ @State private var isShowingAssignSpeakers = false
+ @State private var assignSpeakersFocus: SessionSpeakerID?
+
+ /// Naming is reached by clicking a speaker's name, so the sheet opens on the one clicked.
+ private func presentAssignSpeakers(focusing speakerID: SessionSpeakerID?) {
+ guard self.isQuiescent, !self.session.activeSpeakers.isEmpty else { return }
+ self.assignSpeakersFocus = speakerID
+ self.isShowingAssignSpeakers = true
+ }
private var speakerNames: [SessionSpeakerID: String] {
Dictionary(uniqueKeysWithValues: self.session.activeSpeakers.map { ($0.id, $0.displayName) })
}
+ private func chipTint(for speaker: MeetingSessionSpeaker) -> Color? {
+ speaker.isLocalUser ? self.theme.palette.accent : self.speakerTints[speaker.id]
+ }
+
+ private var speakerTints: [SessionSpeakerID: Color] {
+ MeetingSpeakerPalette.tints(for: self.session.activeSpeakers)
+ }
+
private var hasEchoSegments: Bool {
self.session.transcriptSegments.contains(where: \.isEcho)
}
@@ -2415,14 +2559,14 @@ private struct MeetingResultCanvas: View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: self.theme.metrics.spacing.sm) {
ForEach(activeSpeakers) { speaker in
- Label(
- self.displayName(for: speaker),
- systemImage: speaker.isLocalUser ? "person.crop.circle.badge.checkmark" : "person.crop.circle"
+ MeetingSpeakerChip(
+ title: self.displayName(for: speaker),
+ systemImage: speaker.isLocalUser
+ ? "person.crop.circle.badge.checkmark" : "person.crop.circle",
+ tint: self.chipTint(for: speaker) ?? self.theme.palette.primaryText,
+ action: { self.presentAssignSpeakers(focusing: speaker.id) }
)
- .font(self.theme.typography.badge)
- .padding(.horizontal, self.theme.metrics.spacing.md)
- .padding(.vertical, self.theme.metrics.spacing.sm)
- .background(self.theme.palette.contentBackground, in: Capsule())
+ .disabled(!self.isQuiescent)
.contextMenu { self.speakerChipMenu(for: speaker) }
}
}
@@ -2442,6 +2586,10 @@ private struct MeetingResultCanvas: View {
MeetingTranscriptSegmentRow(
segment: row.segment,
speakerName: row.segment.speakerID.flatMap { speakerNames[$0] } ?? "Unknown speaker",
+ speakerTint: row.segment.speakerID.flatMap { speakerTints[$0] },
+ onRenameSpeakerTapped: row.segment.speakerID.map { speakerID in
+ { self.presentAssignSpeakers(focusing: speakerID) }
+ },
isLocalUser: row.isLocal,
showsSpeakerLabel: row.showsLabel,
reassignTargets: activeSpeakers.filter { $0.id != row.segment.speakerID },
@@ -2503,7 +2651,23 @@ private struct MeetingResultCanvas: View {
Text("Enter a new title for this meeting.")
}
// Prevents an echo toggle left on for one meeting from leaking into the next.
- .onChange(of: self.session.id) { _, _ in self.showsProbableEchoes = false }
+ .onChange(of: self.session.id) { _, _ in
+ self.showsProbableEchoes = false
+ self.isShowingAssignSpeakers = false
+ }
+ .sheet(isPresented: self.$isShowingAssignSpeakers) {
+ MeetingAssignSpeakersSheet(
+ speakers: self.session.activeSpeakers,
+ quotesBySpeaker: Dictionary(uniqueKeysWithValues: self.session.activeSpeakers.map {
+ ($0.id, MeetingAssignSpeakersQuoteSource.sampleQuotes(for: $0.id, in: self.session.transcriptSegments))
+ }),
+ tints: self.speakerTints,
+ accentColor: self.theme.palette.accent,
+ focusedSpeakerID: self.assignSpeakersFocus,
+ onSave: self.onAssignSpeakers,
+ onCancel: { self.isShowingAssignSpeakers = false }
+ )
+ }
}
@ViewBuilder
@@ -2815,9 +2979,44 @@ private struct MeetingTrackHealthRow: View {
}
}
+private struct MeetingSpeakerChip: View {
+ let title: String
+ let systemImage: String
+ let tint: Color
+ let action: () -> Void
+
+ @Environment(\.theme) private var theme
+ @Environment(\.isEnabled) private var isEnabled
+ @State private var isHovering = false
+
+ var body: some View {
+ Button(action: self.action) {
+ HStack(spacing: 3) {
+ Label(self.title, systemImage: self.systemImage)
+ Image(systemName: "chevron.right")
+ .font(.system(size: 9, weight: .semibold))
+ .opacity(self.isHovering ? 1 : 0.45)
+ }
+ .font(self.theme.typography.badge)
+ .foregroundStyle(self.tint)
+ .padding(.horizontal, self.theme.metrics.spacing.md)
+ .padding(.vertical, self.theme.metrics.spacing.sm)
+ .background(self.tint.opacity(self.isHovering ? 0.20 : 0.12), in: Capsule())
+ .overlay(Capsule().strokeBorder(self.tint.opacity(self.isHovering ? 0.45 : 0.22)))
+ }
+ .buttonStyle(.plain)
+ .help("Rename this speaker")
+ .accessibilityLabel("Rename \(self.title)")
+ .pointerStyle(self.isEnabled ? .link : nil)
+ .onHover { self.isHovering = self.isEnabled && $0 }
+ }
+}
+
private struct MeetingTranscriptSegmentRow: View {
let segment: MeetingTranscriptSegment
let speakerName: String
+ let speakerTint: Color?
+ let onRenameSpeakerTapped: (() -> Void)?
let isLocalUser: Bool
let showsSpeakerLabel: Bool
let reassignTargets: [MeetingSessionSpeaker]
@@ -2825,6 +3024,7 @@ private struct MeetingTranscriptSegmentRow: View {
let onReassign: (SessionSpeakerID) -> Void
@Environment(\.theme) private var theme
+ @State private var isHoveringSpeaker = false
var body: some View {
Group {
@@ -2851,12 +3051,53 @@ private struct MeetingTranscriptSegmentRow: View {
)
}
+ /// A wash of the speaker's own tint, faint enough that a wall of turns still reads as text.
+ private var bubbleFill: Color {
+ (self.isLocalUser ? self.theme.palette.accent : self.speakerTint)?.opacity(0.10)
+ ?? self.theme.palette.contentBackground
+ }
+
+ private var speakerLabel: some View {
+ let name = Text(self.speakerName)
+ .foregroundColor(self.nameColor)
+ .fontWeight(.semibold)
+ .font(.system(size: 14, design: .monospaced))
+
+ return HStack(spacing: 8) {
+ if let onRenameSpeakerTapped = self.onRenameSpeakerTapped {
+ Button(action: onRenameSpeakerTapped) {
+ HStack(spacing: 3) {
+ name
+ // Always shown, not hover-only, so the affordance survives an unfocused window.
+ Image(systemName: "chevron.right")
+ .font(.system(size: 10, weight: .semibold))
+ .foregroundColor(self.nameColor)
+ .opacity(self.isHoveringSpeaker ? 1 : 0.45)
+ }
+ }
+ .buttonStyle(.plain)
+ // No .help here: the tooltip lands on top of the turn's first line of text.
+ .accessibilityLabel("Rename \(self.speakerName)")
+ .pointerStyle(.link)
+ .onHover { self.isHoveringSpeaker = $0 }
+ } else {
+ name
+ }
+ Text(MeetingTranscriptExporter.timestampText(self.segment.start.seconds))
+ .font(.system(size: 14, design: .monospaced))
+ .foregroundColor(self.theme.palette.tertiaryText)
+ }
+ }
+
+ private var nameColor: Color {
+ if self.isLocalUser { return self.theme.palette.accent }
+ return self.speakerTint ?? self.theme.palette.tertiaryText
+ }
+
private var localBubble: some View {
VStack(alignment: .trailing, spacing: 6) {
if self.showsSpeakerLabel {
- Text("\(self.speakerName) · \(MeetingTranscriptExporter.timestampText(self.segment.start.seconds))")
- .font(.system(size: 12, design: .monospaced))
- .foregroundStyle(self.theme.palette.tertiaryText)
+ self.speakerLabel
}
Text(self.segment.text)
.font(.system(size: 15, design: .monospaced))
@@ -2865,10 +3106,7 @@ private struct MeetingTranscriptSegmentRow: View {
.textSelection(.enabled)
.padding(.horizontal, 18)
.padding(.vertical, 12)
- .background(
- self.theme.palette.contentBackground,
- in: RoundedRectangle(cornerRadius: 18, style: .continuous)
- )
+ .background(self.bubbleFill, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
if self.segment.isEcho {
Text("probable echo")
.font(self.theme.typography.caption)
@@ -2882,15 +3120,16 @@ private struct MeetingTranscriptSegmentRow: View {
private var remoteMessage: some View {
VStack(alignment: .leading, spacing: 6) {
if self.showsSpeakerLabel {
- Text("\(self.speakerName) · \(MeetingTranscriptExporter.timestampText(self.segment.start.seconds))")
- .font(.system(size: 12, design: .monospaced))
- .foregroundStyle(self.theme.palette.tertiaryText)
+ self.speakerLabel
}
Text(self.segment.text)
.font(.system(size: 15, design: .monospaced))
.lineSpacing(5)
.foregroundStyle(self.theme.palette.primaryText)
.textSelection(.enabled)
+ .padding(.horizontal, 18)
+ .padding(.vertical, 12)
+ .background(self.bubbleFill, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
if self.segment.isEcho {
Text("probable echo")
.font(self.theme.typography.caption)
diff --git a/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift
new file mode 100644
index 00000000..cd9fb5ee
--- /dev/null
+++ b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift
@@ -0,0 +1,215 @@
+@testable import FluidVoice_Debug
+import CoreMedia
+import Foundation
+import XCTest
+
+final class MeetingLiveTimeConversionTests: XCTestCase {
+ func testZeroOriginPassesPTSThrough() {
+ let pts = CMTime(value: 5, timescale: 1)
+ let origin = CMTime(value: 0, timescale: 1)
+ XCTAssertEqual(MeetingLiveTimeConversion.sessionSeconds(pts: pts, origin: origin), 5, accuracy: 0.001)
+ }
+
+ func testNonZeroOriginSubtracts() {
+ let pts = CMTime(value: 7, timescale: 1)
+ let origin = CMTime(value: 2, timescale: 1)
+ XCTAssertEqual(MeetingLiveTimeConversion.sessionSeconds(pts: pts, origin: origin), 5, accuracy: 0.001)
+ }
+
+ func testPTSBeforeOriginClampsToZero() {
+ let pts = CMTime(value: 1, timescale: 1)
+ let origin = CMTime(value: 4, timescale: 1)
+ XCTAssertEqual(MeetingLiveTimeConversion.sessionSeconds(pts: pts, origin: origin), 0, accuracy: 0.001)
+ }
+
+ func testInvalidTimesReturnZero() {
+ XCTAssertEqual(MeetingLiveTimeConversion.sessionSeconds(pts: .invalid, origin: .zero), 0)
+ }
+
+ func testOriginBoxKeepsTheEarliestPTS() {
+ let box = MeetingLiveOriginBox()
+ XCTAssertEqual(box.establish(CMTime(value: 5, timescale: 1)), CMTime(value: 5, timescale: 1))
+ // A later-arriving but earlier PTS (out-of-order tee delivery) still wins.
+ XCTAssertEqual(box.establish(CMTime(value: 2, timescale: 1)), CMTime(value: 2, timescale: 1))
+ XCTAssertEqual(box.establish(CMTime(value: 9, timescale: 1)), CMTime(value: 2, timescale: 1))
+ }
+}
+
+final class MeetingLiveTranscriptSnapshotTests: XCTestCase {
+ private func utterance(_ speaker: MeetingLiveSpeaker, _ text: String, start: TimeInterval, end: TimeInterval) -> MeetingLiveUtterance {
+ MeetingLiveUtterance(id: UUID(), speaker: speaker, text: text, start: start, end: end)
+ }
+
+ func testInsertingKeepsUtterancesSortedByStart() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.inserting(self.utterance(.you, "second", start: 5, end: 6))
+ snapshot = snapshot.inserting(self.utterance(.them, "first", start: 1, end: 2))
+ snapshot = snapshot.inserting(self.utterance(.you, "third", start: 8, end: 9))
+ XCTAssertEqual(snapshot.utterances.map(\.text), ["first", "second", "third"])
+ }
+
+ /// A later-arriving finalize whose audio started earlier must still sort before an
+ /// already-published utterance with a later start — engines finalize independently.
+ func testLaterArrivingEarlierStartSortsFirst() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.inserting(self.utterance(.them, "arrived first, starts late", start: 10, end: 12))
+ snapshot = snapshot.inserting(self.utterance(.you, "arrived second, starts early", start: 3, end: 4))
+ XCTAssertEqual(snapshot.utterances.first?.text, "arrived second, starts early")
+ }
+
+ func testGrowingPartialsReplaceRatherThanConcatenate() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.settingPartial("hel", for: .you)
+ snapshot = snapshot.settingPartial("hello", for: .you)
+ snapshot = snapshot.settingPartial("hello there", for: .you)
+ XCTAssertEqual(snapshot.partials[.you], "hello there")
+ }
+
+ func testEmptyPartialClearsTheSlot() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.settingPartial("hello", for: .them)
+ snapshot = snapshot.settingPartial("", for: .them)
+ XCTAssertNil(snapshot.partials[.them])
+ }
+
+ func testPartialsForEachSpeakerAreIndependent() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.settingPartial("you partial", for: .you)
+ snapshot = snapshot.settingPartial("them partial", for: .them)
+ XCTAssertEqual(snapshot.partials[.you], "you partial")
+ XCTAssertEqual(snapshot.partials[.them], "them partial")
+ }
+}
+
+final class MeetingLiveBoundedQueueTests: XCTestCase {
+ func testEnqueueUnderCapacityNeverDrops() {
+ let queue = MeetingLiveBoundedQueue<Int>(capacity: 4)
+ for value in 0..<4 {
+ XCTAssertFalse(queue.enqueue(value))
+ }
+ XCTAssertEqual(queue.drainAll(), [0, 1, 2, 3])
+ }
+
+ func testSaturationDropsTheOldestElement() {
+ let queue = MeetingLiveBoundedQueue<Int>(capacity: 3)
+ for value in 0..<3 { _ = queue.enqueue(value) }
+ let dropped = queue.enqueue(3)
+ XCTAssertTrue(dropped)
+ // 0 was the oldest; it must be gone, newest (3) must be present.
+ XCTAssertEqual(queue.drainAll(), [1, 2, 3])
+ }
+
+ func testDrainClearsTheQueue() {
+ let queue = MeetingLiveBoundedQueue<Int>(capacity: 4)
+ _ = queue.enqueue(1)
+ _ = queue.drainAll()
+ XCTAssertEqual(queue.drainAll(), [])
+ }
+
+ func testHeavySaturationNeverGrowsPastCapacity() {
+ let queue = MeetingLiveBoundedQueue<Int>(capacity: 4)
+ for value in 0..<1000 { _ = queue.enqueue(value) }
+ let drained = queue.drainAll()
+ XCTAssertEqual(drained.count, 4)
+ XCTAssertEqual(drained, [996, 997, 998, 999])
+ }
+}
+
+final class MeetingLiveEchoFilterTests: XCTestCase {
+ func testMicUtteranceMatchingRecentThemTextIsSuppressed() {
+ let them = [
+ MeetingLiveUtterance(
+ id: UUID(), speaker: .them,
+ text: "let's push the release to next Tuesday afternoon",
+ start: 10, end: 14
+ ),
+ ]
+ let recent = MeetingLiveEchoFilter.recentThemText(from: them, before: 15, windowSeconds: 20)
+ let shouldSuppress = MeetingLiveEchoFilter.shouldSuppress(
+ micText: "let's push the release to next Tuesday afternoon",
+ recentThemText: recent
+ )
+ XCTAssertTrue(shouldSuppress)
+ }
+
+ func testGenuineLocalUtteranceIsNotSuppressed() {
+ let them = [
+ MeetingLiveUtterance(id: UUID(), speaker: .them, text: "let's push the release to next Tuesday", start: 10, end: 14),
+ ]
+ let recent = MeetingLiveEchoFilter.recentThemText(from: them, before: 15, windowSeconds: 20)
+ let shouldSuppress = MeetingLiveEchoFilter.shouldSuppress(
+ micText: "I think we should grab lunch after this call",
+ recentThemText: recent
+ )
+ XCTAssertFalse(shouldSuppress)
+ }
+
+ func testThemTextOutsideTheWindowIsExcluded() {
+ let them = [
+ MeetingLiveUtterance(id: UUID(), speaker: .them, text: "let's push the release to next Tuesday afternoon", start: 0, end: 2),
+ ]
+ let recent = MeetingLiveEchoFilter.recentThemText(from: them, before: 100, windowSeconds: 20)
+ XCTAssertTrue(recent.isEmpty)
+ XCTAssertFalse(MeetingLiveEchoFilter.shouldSuppress(micText: "let's push the release to next Tuesday afternoon", recentThemText: recent))
+ }
+}
+
+final class MeetingLiveMemoryGateTests: XCTestCase {
+ func testBelowThresholdDisablesLive() {
+ let oneGigabyte: UInt64 = 1 * 1_024 * 1_024 * 1_024
+ XCTAssertFalse(MeetingLiveTranscriptionCoordinator.isMemorySufficient(physicalMemory: oneGigabyte))
+ }
+
+ func testAtOrAboveThresholdAllowsLive() {
+ XCTAssertTrue(MeetingLiveTranscriptionCoordinator.isMemorySufficient(
+ physicalMemory: MeetingLiveTranscriptionCoordinator.minimumPhysicalMemoryBytes
+ ))
+ XCTAssertTrue(MeetingLiveTranscriptionCoordinator.isMemorySufficient(physicalMemory: 64 * 1_024 * 1_024 * 1_024))
+ }
+}
+
+final class MeetingLiveProvisionalContainmentTests: XCTestCase {
+ /// Provisional live text must never reach the exporter: it only ever reads `MeetingSession`,
+ /// and live utterances are never written into `session.transcriptSegments`.
+ func testExportedTranscriptNeverContainsLiveOnlyText() {
+ let microphone = MeetingMicrophoneIdentity(captureDeviceID: "mic-1", coreAudioUID: nil, displayName: "Test Mic")
+ let configuration = MeetingCaptureConfiguration(mode: .inRoom, title: "Standup", microphone: microphone)
+ let timebase = MeetingTimebaseMetadata(startedHostTime: 0, machTimebaseNumerator: 1, machTimebaseDenominator: 1, firstPresentationTime: nil)
+ var session = MeetingSession(configuration: configuration, timebase: timebase)
+
+ let speakerID = UUID()
+ session.speakers = [
+ MeetingSessionSpeaker(
+ id: speakerID, displayName: "Speaker 1", diarizationClusterID: nil,
+ trackKind: .microphone, isLocalUser: true, identityCandidates: []
+ ),
+ ]
+ session.transcriptSegments = [
+ MeetingTranscriptSegment(
+ id: UUID(),
+ start: MeetingMediaTime(value: 0, timescale: 1),
+ end: MeetingMediaTime(value: 1, timescale: 1),
+ sourceTrackID: UUID(),
+ speakerID: speakerID,
+ text: "FINAL_TRANSCRIPT_TEXT",
+ revision: 0,
+ status: .final,
+ overlap: .none,
+ completeness: .complete
+ ),
+ ]
+
+ // A live snapshot exists in memory alongside the session, as it would during recording,
+ // but nothing ever threads it into the exporter or the session's segments.
+ let liveSnapshot = MeetingLiveTranscriptSnapshot.empty
+ .inserting(MeetingLiveUtterance(id: UUID(), speaker: .you, text: "PROVISIONAL_LIVE_ONLY_TEXT", start: 0, end: 1))
+ .settingPartial("PROVISIONAL_PARTIAL_ONLY_TEXT", for: .them)
+
+ let exported = MeetingTranscriptExporter.text(for: session, includeEchoes: true)
+ XCTAssertTrue(exported.contains("FINAL_TRANSCRIPT_TEXT"))
+ XCTAssertFalse(exported.contains("PROVISIONAL_LIVE_ONLY_TEXT"))
+ XCTAssertFalse(exported.contains("PROVISIONAL_PARTIAL_ONLY_TEXT"))
+ XCTAssertFalse(session.transcriptSegments.contains { $0.text.contains("PROVISIONAL") })
+ XCTAssertFalse(liveSnapshot.utterances.isEmpty, "sanity: the live snapshot really did hold provisional content")
+ }
+}
diff --git a/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift b/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
index 01c1ec59..7f73f468 100644
--- a/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
+++ b/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
@@ -1,4 +1,5 @@
@testable import FluidVoice_Debug
+import CoreMedia
import Foundation
import SwiftUI
import XCTest
@@ -1657,6 +1658,252 @@ final class MeetingRecoveryTests: XCTestCase {
XCTAssertEqual(undoCount, 50)
}
+ // MARK: - Batched speaker rename (Assign speakers sheet)
+
+ func testRenameSpeakersAppliesEveryChangedNameInOneCall() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ let result = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: "Erik", speakerB: "Maya"]
+ )
+
+ let namesByID = Dictionary(uniqueKeysWithValues: result.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Erik")
+ XCTAssertEqual(namesByID[speakerB], "Maya")
+ }
+
+ func testRenameSpeakersSkipsBlankAndUnchangedAndNoOpsIfAllSkipped() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ // Every entry is either blank or equal to the current name: nothing should change or save.
+ _ = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: " ", speakerB: "Speaker B"]
+ )
+
+ XCTAssertFalse(coordinator.canUndoCorrection(sessionID: session.id))
+ let reloaded = try await store.load(id: session.id)
+ let namesByID = Dictionary(uniqueKeysWithValues: reloaded?.speakers.map { ($0.id, $0.displayName) } ?? [])
+ XCTAssertEqual(namesByID[speakerA], "Speaker A")
+ XCTAssertEqual(namesByID[speakerB], "Speaker B")
+ }
+
+ func testRenameSpeakersSkipsBlankPartiallyAndAppliesTheRest() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ let result = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: "Erik", speakerB: ""]
+ )
+
+ let namesByID = Dictionary(uniqueKeysWithValues: result.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Erik")
+ XCTAssertEqual(namesByID[speakerB], "Speaker B")
+ XCTAssertTrue(coordinator.canUndoCorrection(sessionID: session.id))
+ }
+
+ func testUndoAfterBatchRenameRestoresAllPreviousNames() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ _ = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: "Erik", speakerB: "Maya"]
+ )
+ let undone = try await coordinator.undoTranscriptCorrection(sessionID: session.id)
+
+ let namesByID = Dictionary(uniqueKeysWithValues: undone.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Speaker A")
+ XCTAssertEqual(namesByID[speakerB], "Speaker B")
+ XCTAssertFalse(coordinator.canUndoCorrection(sessionID: session.id))
+ }
+
+ func testRenameSpeakersIgnoresAMergedSpeakerInTheMap() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ _ = try await coordinator.mergeSpeakers(sessionID: session.id, source: speakerB, into: speakerA)
+
+ let result = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: "Erik", speakerB: "ShouldBeIgnored"]
+ )
+
+ let namesByID = Dictionary(uniqueKeysWithValues: result.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Erik")
+ XCTAssertEqual(namesByID[speakerB], "Speaker B")
+ }
+
+ func testBatchRenameThenSingleRenameThenTwoUndosRestoreInLIFOOrder() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ let (session, speakerA, speakerB, _) = self.makeCorrectionSession(state: .completed)
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store, capture: StubCaptureController(), processing: StubProcessingController(), audioArbiter: StubArbiter()
+ )
+
+ _ = try await coordinator.renameSpeakers(
+ sessionID: session.id,
+ names: [speakerA: "Erik", speakerB: "Maya"]
+ )
+ _ = try await coordinator.renameSpeaker(sessionID: session.id, speakerID: speakerA, to: "Erik II")
+
+ var undone = try await coordinator.undoTranscriptCorrection(sessionID: session.id)
+ var namesByID = Dictionary(uniqueKeysWithValues: undone.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Erik")
+ XCTAssertEqual(namesByID[speakerB], "Maya")
+
+ undone = try await coordinator.undoTranscriptCorrection(sessionID: session.id)
+ namesByID = Dictionary(uniqueKeysWithValues: undone.speakers.map { ($0.id, $0.displayName) })
+ XCTAssertEqual(namesByID[speakerA], "Speaker A")
+ XCTAssertEqual(namesByID[speakerB], "Speaker B")
+ XCTAssertFalse(coordinator.canUndoCorrection(sessionID: session.id))
+ }
+
+ // MARK: - MeetingSpeakerPalette.tintIndices
+
+ func testTintIndicesRenamingUnknownMicPlaceholderDoesNotShiftOtherIndices() {
+ let speakerA = self.makeSpeaker(name: "Speaker A")
+ let placeholder = self.makeSpeaker(name: MeetingSpeakerPalette.unknownMicrophoneSpeakerName)
+ let speakerC = self.makeSpeaker(name: "Speaker C")
+
+ let before = MeetingSpeakerPalette.tintIndices(for: [speakerA, placeholder, speakerC])
+ XCTAssertEqual(before[speakerA.id], 0)
+ XCTAssertNil(before[placeholder.id])
+ XCTAssertEqual(before[speakerC.id], 2)
+ XCTAssertNil(MeetingSpeakerPalette.tints(for: [speakerA, placeholder, speakerC])[placeholder.id])
+
+ var renamedPlaceholder = placeholder
+ renamedPlaceholder.displayName = "Jordan"
+ let after = MeetingSpeakerPalette.tintIndices(for: [speakerA, renamedPlaceholder, speakerC])
+ XCTAssertEqual(after[speakerA.id], 0)
+ XCTAssertEqual(after[renamedPlaceholder.id], 1)
+ XCTAssertEqual(after[speakerC.id], 2)
+ XCTAssertNotNil(MeetingSpeakerPalette.tints(for: [speakerA, renamedPlaceholder, speakerC])[renamedPlaceholder.id])
+ }
+
+ // MARK: - MeetingAssignSpeakersValidation.duplicateName
+
+ func testDuplicateNameIgnoresACollisionTheUserDidNotCreate() {
+ let first = self.makeSpeaker(name: "Speaker")
+ let second = self.makeSpeaker(name: "Speaker")
+ let current = [(id: first.id, displayName: first.displayName), (id: second.id, displayName: second.displayName)]
+
+ XCTAssertNil(MeetingAssignSpeakersValidation.duplicateName(current: current, drafts: [:]))
+ XCTAssertNil(
+ MeetingAssignSpeakersValidation.duplicateName(
+ current: current,
+ drafts: [first.id: "Speaker", second.id: " "]
+ ),
+ "a blank draft means leave unchanged, so the pre-existing collision must stay savable"
+ )
+ XCTAssertNil(
+ MeetingAssignSpeakersValidation.duplicateName(
+ current: current,
+ drafts: [first.id: "Erik"]
+ ),
+ "resolving one half of a pre-existing collision must not be blocked by the other half"
+ )
+ }
+
+ func testDuplicateNameFlagsACollisionTheUserCreatedRegardlessOfCaseOrPadding() {
+ let first = self.makeSpeaker(name: "Erik")
+ let second = self.makeSpeaker(name: "Speaker 2")
+ let current = [(id: first.id, displayName: first.displayName), (id: second.id, displayName: second.displayName)]
+
+ XCTAssertEqual(
+ MeetingAssignSpeakersValidation.duplicateName(current: current, drafts: [second.id: " erik "]),
+ "erik"
+ )
+ }
+
+ // MARK: - MeetingAssignSpeakersQuoteSource.sampleQuotes
+
+ func testSampleQuotesExcludesEchoAndNonFinalOrdersByStartTimeCapsAtTwo() {
+ let track = self.makeMicrophoneTrack(chunks: [self.makeFinalizedChunk()])
+ let speakerID = SessionSpeakerID()
+
+ func segment(
+ text: String,
+ startSeconds: Int64,
+ status: MeetingTranscriptStatus = .final,
+ isEcho: Bool = false
+ ) -> MeetingTranscriptSegment {
+ var segment = self.makeTranscriptSegment(sourceTrackID: track.id, speakerID: speakerID)
+ segment.text = text
+ segment.start = MeetingMediaTime(value: startSeconds, timescale: 1)
+ segment.status = status
+ segment.isLikelyEcho = isEcho
+ return segment
+ }
+
+ let segments = [
+ segment(text: "Third, out of order", startSeconds: 30),
+ segment(text: "An echoed line", startSeconds: 5, isEcho: true),
+ segment(text: "A provisional line", startSeconds: 8, status: .provisional),
+ segment(text: "First thing said", startSeconds: 10),
+ segment(text: "Second thing said", startSeconds: 20),
+ ]
+
+ let quotes = MeetingAssignSpeakersQuoteSource.sampleQuotes(for: speakerID, in: segments)
+ XCTAssertEqual(quotes, ["First thing said", "Second thing said"])
+ }
+
+ func testSampleQuotesTruncatesLongTextOnAWordBoundary() {
+ let track = self.makeMicrophoneTrack(chunks: [self.makeFinalizedChunk()])
+ let speakerID = SessionSpeakerID()
+ var segment = self.makeTranscriptSegment(sourceTrackID: track.id, speakerID: speakerID)
+ segment.text = Array(repeating: "word", count: 60).joined(separator: " ")
+
+ let quotes = MeetingAssignSpeakersQuoteSource.sampleQuotes(for: speakerID, in: [segment])
+ XCTAssertEqual(quotes.count, 1)
+ XCTAssertTrue(quotes[0].hasSuffix("…"))
+ XCTAssertLessThanOrEqual(quotes[0].count, 181)
+ XCTAssertFalse(quotes[0].dropLast().contains(" …"))
+ }
+
// MARK: - Audio retention & delete audio
private func withRetentionPolicy<T>(
@@ -2495,7 +2742,8 @@ private final class StubCaptureController: MeetingCaptureControlling, @unchecked
session: MeetingSession,
configuration: MeetingCaptureConfiguration,
sessionDirectory: URL,
- eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void
+ eventHandler: @escaping @Sendable (MeetingCaptureEvent) -> Void,
+ liveAudioHandler: (@Sendable (MeetingAudioTrackKind, CMSampleBuffer) -> Void)?
) async throws -> MeetingCaptureStartResult {
await self.onStart?()
if let startError { throw startError }