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
fix(meeting): usable transcripts and working echo suppression without word timings
Shreeraman A K86831d8e4419
diff --git a/Sources/Fluid/Services/Meeting/MeetingEchoDetector.swift b/Sources/Fluid/Services/Meeting/MeetingEchoDetector.swiftindex 165fdaff..da216b7e 100644--- a/Sources/Fluid/Services/Meeting/MeetingEchoDetector.swift+++ b/Sources/Fluid/Services/Meeting/MeetingEchoDetector.swift@@ -4,7 +4,11 @@ import Foundationnonisolated enum MeetingEchoDetector {static let minimumMicWords = 4static let minimumMatchedContentWords = 2- static let containmentThreshold = 0.75+ /// Measured on one real call: echo 0.65-1.00 at any length, non-echo 0.00-0.33.+ static let containmentThreshold = 0.5++ /// Below this the ratio quantises too coarsely to trust a partial hit; demand a total match.+ static let minimumContentWordsForPartialMatch = 4private static let stopwords: Set<String> = ["the", "a", "an", "and", "or", "but", "so", "to", "of", "in", "on", "it", "is",@@ -32,10 +36,13 @@ nonisolated enum MeetingEchoDetector {}static func isLikelyEcho(micText: String, remoteText: String) -> Bool {- let micWords = Set(self.normalizedWords(micText))- guard micWords.count >= self.minimumMicWords else { return false }+ guard self.normalizedWords(micText).count >= self.minimumMicWords else { return false }let matchedContentWords = self.contentWords(micText).intersection(self.contentWords(remoteText)).countguard matchedContentWords >= self.minimumMatchedContentWords else { return false }- return self.containment(micText: micText, remoteText: remoteText) >= self.containmentThreshold+ let score = self.containment(micText: micText, remoteText: remoteText)+ if self.contentWords(micText).count < self.minimumContentWordsForPartialMatch {+ return score >= 1+ }+ return score >= self.containmentThreshold}}diff --git a/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift b/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swiftindex 70413349..ce516317 100644--- a/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift+++ b/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift@@ -279,6 +279,35 @@ private final class MeetingProviderLanguagePin {@MainActorfinal class MeetingProcessingPipeline: MeetingProcessingControlling {static let pipelineVersion = 3+ /// Per-turn engines starve on short turns, and an all-empty chunk collapses to unlabeled.+ static let perTurnTurnMergeGapSeconds = 5.0++ /// Gap alone produced ~59s turns, too coarse to attribute. Bound the length as well.+ static let meetingTurnMaxSeconds = 30.0+++ nonisolated static func turnMergeGapSeconds(supportsWordTimings: Bool) -> TimeInterval {+ supportsWordTimings ? Self.meetingTurnMergeGapSeconds : Self.perTurnTurnMergeGapSeconds+ }++ /// Claiming the whole chunk marks every concurrent mic turn as overlapping remote, erasing+ /// the clean-speech evidence that identifies "You".+ nonisolated static func isEmptyTurnFallback(_ error: Error) -> Bool {+ if case LabeledPassError.emptyTurn = error { return true }+ return false+ }++ nonisolated static func remoteFallbackIntervals(+ diarizedTurns: [(start: TimeInterval, end: TimeInterval)],+ chunkOffset: TimeInterval,+ chunkDuration: TimeInterval+ ) -> [(start: TimeInterval, end: TimeInterval)] {+ guard !diarizedTurns.isEmpty else {+ return [(start: chunkOffset, end: chunkOffset + chunkDuration)]+ }+ return diarizedTurns.map { (start: chunkOffset + $0.start, end: chunkOffset + $0.end) }+ }+/// Conversational pauses run to a few seconds; 1.0s fragmented turns and starved the ASR.static let meetingTurnMergeGapSeconds = 3.0@@ -674,10 +703,16 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {let chunkDuration = try await Task.detached(priority: .userInitiated) {try Self.audioDuration(url)}.value+ var diarizedSpans: [(start: TimeInterval, end: TimeInterval)] = []if SpeakerDiarizationService.isSupported {do {- let diarization = try await diarizer.diarizeWithProfiles(fileURL: url, maxGapSeconds: Self.meetingTurnMergeGapSeconds)+ let diarization = try await diarizer.diarizeWithProfiles(+ fileURL: url,+ maxGapSeconds: Self.turnMergeGapSeconds(supportsWordTimings: context.provider.supportsWordTimings),+ maxTurnSeconds: Self.meetingTurnMaxSeconds+ )let turns = diarization.turns+ diarizedSpans = turns.map { (start: $0.startSeconds, end: $0.endSeconds) }if !turns.isEmpty {let allTurns = try await self.transcribeTurns(turns, chunkID: chunk.id, trackKind: .applicationAudio, fileURL: url, context: context)guard let transcribedTurns = MeetingTurnSelection.keepingNonEmpty(allTurns) else {@@ -742,8 +777,9 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {} catch {if error is CancellationError { throw error }if case MeetingProcessingError.audioUnreadable = error { throw error }+ let reason = Self.isEmptyTurnFallback(error) ? "every turn transcribed empty" : "diarization failed"DebugLogger.shared.warning(- "Meeting remote diarization failed; preserving an unlabeled track transcript: \(error)",+ "Meeting remote chunk \(chunk.id) fell back to an unlabeled transcript (\(reason)): \(error)",source: "MeetingProcessingPipeline")}@@ -763,7 +799,11 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {isLocalUser: false,clusterID: nil)- remoteSpeech.append(TimelineInterval(start: chunkOffset, end: chunkOffset + chunkDuration))+ remoteSpeech.append(contentsOf: Self.remoteFallbackIntervals(+ diarizedTurns: diarizedSpans,+ chunkOffset: chunkOffset,+ chunkDuration: chunkDuration+ ).map { TimelineInterval(start: $0.start, end: $0.end) })accumulator.segments.append(Self.segment(key: "remote-fallback:\(chunk.id.uuidString)",trackID: track.id,@@ -838,7 +878,11 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {}.valueif SpeakerDiarizationService.isSupported {do {- let diarization = try await diarizer.diarizeWithProfiles(fileURL: url, maxGapSeconds: Self.meetingTurnMergeGapSeconds)+ let diarization = try await diarizer.diarizeWithProfiles(+ fileURL: url,+ maxGapSeconds: Self.turnMergeGapSeconds(supportsWordTimings: context.provider.supportsWordTimings),+ maxTurnSeconds: Self.meetingTurnMaxSeconds+ )let turns = diarization.turnsif !turns.isEmpty {let allTurns = try await self.transcribeTurns(turns, chunkID: chunk.id, trackKind: .microphone, fileURL: url, context: context)@@ -889,8 +933,9 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {} catch {if error is CancellationError { throw error }if case MeetingProcessingError.audioUnreadable = error { throw error }+ let reason = Self.isEmptyTurnFallback(error) ? "every turn transcribed empty" : "diarization failed"DebugLogger.shared.warning(- "Meeting microphone speech detection failed; preserving an unlabeled track transcript: \(error)",+ "Meeting microphone chunk \(chunk.id) fell back to an unlabeled transcript (\(reason)): \(error)",source: "MeetingProcessingPipeline")}diff --git a/Sources/Fluid/Services/SpeakerDiarizationService.swift b/Sources/Fluid/Services/SpeakerDiarizationService.swiftindex 29379305..4775526b 100644--- a/Sources/Fluid/Services/SpeakerDiarizationService.swift+++ b/Sources/Fluid/Services/SpeakerDiarizationService.swift@@ -52,7 +52,11 @@ actor SpeakerDiarizationService {/// Includes one bounded centroid per local cluster so callers can stitch the/// same voice across independently processed files without retaining audio./// - Parameter maxGapSeconds: file transcription keeps the 1.0s default; meetings pass wider.- func diarizeWithProfiles(fileURL: URL, maxGapSeconds: Double = 1.0) async throws -> DiarizationOutput {+ func diarizeWithProfiles(+ fileURL: URL,+ maxGapSeconds: Double = 1.0,+ maxTurnSeconds: Double = 20 * 60+ ) async throws -> DiarizationOutput {if !self.modelsReady {await MainActor.run {DebugLogger.shared.info(@@ -111,7 +115,7 @@ actor SpeakerDiarizationService {}return DiarizationOutput(- turns: Self.mergeAdjacentTurns(turns, maxGapSeconds: maxGapSeconds),+ turns: Self.mergeAdjacentTurns(turns, maxGapSeconds: maxGapSeconds, maxTurnSeconds: maxTurnSeconds),profilesByLabel: profilesByLabel)}@@ -187,7 +191,11 @@ actor SpeakerDiarizationService {try await self.diarizeWithProfiles(fileURL: fileURL).turns}- func diarizeWithProfiles(fileURL: URL, maxGapSeconds: Double = 1.0) async throws -> DiarizationOutput {+ func diarizeWithProfiles(+ fileURL: URL,+ maxGapSeconds: Double = 1.0,+ maxTurnSeconds: Double = 20 * 60+ ) async throws -> DiarizationOutput {throw NSError(domain: "SpeakerDiarizationService",code: -1,diff --git a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swiftindex a7ca593a..a7532b6b 100644--- a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift+++ b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift@@ -1412,6 +1412,88 @@ final class MeetingSessionModelTests: XCTestCase {XCTAssertEqual(result.byTurn[0], "one two three")}+ // MARK: - Per-turn engines: merge gap, and fallbacks that must not erase "You"++ // Real pairs from one Zoom recording. A user talking alone scores 0 at any length.++ func testLongEchoSegmentIsStillFlagged() {+ let mic = "I'm sure you remember this time at these days. If I get something wrong. myself. you know. did I sign a lucron? The need to verify the work"+ let remote = "I'm sure you remember this time at these days. If I get something wrong, are usually question myself? You know, did I sign a look wrong? Did I not give my agent everything? The need. To verify their work."+ XCTAssertTrue(MeetingEchoDetector.isLikelyEcho(micText: mic, remoteText: remote))+ }++ func testUserSpeakingAloneIsNeverFlaggedRegardlessOfLength() {+ let mic = "This is a test for fluid voice app. Meeting captured. The meeting is getting captured on my machine and I am checking whether the transcript comes out right."+ XCTAssertEqual(MeetingEchoDetector.containment(micText: mic, remoteText: ""), 0)+ XCTAssertFalse(MeetingEchoDetector.isLikelyEcho(micText: mic, remoteText: ""))+ }++ func testOnTopicButDistinctSpeechStaysBelowThreshold() {+ let mic = "I felt it was not terminal. It drops consistent"+ let remote = "the terminal session dropped again and I had to restart the whole thing from scratch"+ XCTAssertLessThan(MeetingEchoDetector.containment(micText: mic, remoteText: remote), MeetingEchoDetector.containmentThreshold)+ }++ func testRepetitiveShortUtteranceIsNotRejectedByTheWordFloor() {+ let mic = "you know you know you know you know"+ XCTAssertTrue(MeetingEchoDetector.normalizedWords(mic).count >= MeetingEchoDetector.minimumMicWords)+ }++ func testMergedTurnsAreLengthCappedNotJustGapMerged() {+ let turns = (0..<20).map {+ SpeakerDiarizationService.SpeakerTurn(+ speakerLabel: "Speaker 1",+ startSeconds: Double($0) * 4,+ endSeconds: Double($0) * 4 + 3.5+ )+ }+ let merged = SpeakerDiarizationService.mergeAdjacentTurns(+ turns,+ maxGapSeconds: MeetingProcessingPipeline.perTurnTurnMergeGapSeconds,+ maxTurnSeconds: MeetingProcessingPipeline.meetingTurnMaxSeconds+ )+ XCTAssertGreaterThan(merged.count, 1, "the cap must break up an unbroken monologue")+ for turn in merged {+ XCTAssertLessThanOrEqual(+ turn.endSeconds - turn.startSeconds,+ MeetingProcessingPipeline.meetingTurnMaxSeconds+ )+ }+ }++ func testMergeGapIsWiderForEnginesWithoutWordTimings() {+ let aligned = MeetingProcessingPipeline.turnMergeGapSeconds(supportsWordTimings: true)+ let perTurn = MeetingProcessingPipeline.turnMergeGapSeconds(supportsWordTimings: false)+ XCTAssertEqual(aligned, MeetingProcessingPipeline.meetingTurnMergeGapSeconds, "aligned path must be unchanged")+ XCTAssertGreaterThan(perTurn, aligned, "per-turn engines merge harder to avoid starved turns")+ }++ func testRemoteFallbackUsesDiarizedSpansWhenAvailable() {+ let intervals = MeetingProcessingPipeline.remoteFallbackIntervals(+ diarizedTurns: [(start: 2, end: 5), (start: 40, end: 44)],+ chunkOffset: 60,+ chunkDuration: 60+ )+ XCTAssertEqual(intervals.count, 2)+ XCTAssertEqual(intervals[0].start, 62)+ XCTAssertEqual(intervals[0].end, 65)+ XCTAssertEqual(intervals[1].start, 100)+ XCTAssertEqual(intervals[1].end, 104)+ let claimed = intervals.reduce(0.0) { $0 + ($1.end - $1.start) }+ XCTAssertLessThan(claimed, 60, "must not claim the whole chunk when spans are known")+ }++ func testRemoteFallbackClaimsWholeChunkWhenDiarizationProducedNothing() {+ let intervals = MeetingProcessingPipeline.remoteFallbackIntervals(+ diarizedTurns: [],+ chunkOffset: 60,+ chunkDuration: 60+ )+ XCTAssertEqual(intervals.count, 1)+ XCTAssertEqual(intervals[0].start, 60)+ XCTAssertEqual(intervals[0].end, 120)+ }+// MARK: - Speaker bleed must never be attached to a local turnfunc testWordAttachmentToleranceIsZeroOnTheMicrophoneTrack() {