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(diarization): stop overlap merge from shrinking speaker turns
Yurii Chukhlib441a87d30373
diff --git a/Sources/Fluid/Services/SpeakerDiarizationService.swift b/Sources/Fluid/Services/SpeakerDiarizationService.swiftindex e21c6de1..1886cdfa 100644--- a/Sources/Fluid/Services/SpeakerDiarizationService.swift+++ b/Sources/Fluid/Services/SpeakerDiarizationService.swift@@ -99,10 +99,15 @@ actor SpeakerDiarizationService {gap <= maxGapSeconds,combinedDuration <= maxTurnSeconds{+ // A merge must never shrink the covered time range. Diarization+ // segments can overlap at boundaries (overlapping speech, VAD+ // imprecision), so a later same-speaker turn may end before the+ // accumulated turn — taking turn.endSeconds directly would drop the+ // trailing audio ([turn.end, current.end]) from the slice.current = SpeakerTurn(speakerLabel: current.speakerLabel,startSeconds: current.startSeconds,- endSeconds: turn.endSeconds+ endSeconds: max(current.endSeconds, turn.endSeconds))} else {merged.append(current)diff --git a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swiftindex 77f00d22..cb3c2522 100644--- a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift+++ b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift@@ -78,6 +78,30 @@ final class SpeakerTurnMergingTests: XCTestCase {XCTAssertEqual(kept.count, 5, "correct labels keep the exchange separated")}+ /// Regression: diarization segments can overlap at boundaries. A later+ /// same-speaker turn that ends inside the accumulated turn used to overwrite+ /// `endSeconds` with its own (earlier) end, dropping the trailing audio.+ func testOverlappingSameSpeakerTurnDoesNotShrinkMergedRange() {+ let merged = SpeakerDiarizationService.mergeAdjacentTurns([+ self.turn("Speaker 1", 0, 10),+ self.turn("Speaker 1", 5, 8),+ ])+ XCTAssertEqual(merged.count, 1)+ XCTAssertEqual(merged[0].startSeconds, 0)+ XCTAssertEqual(merged[0].endSeconds, 10, "a contained turn must not shrink the merged range")+ }++ /// A turn ending exactly at the accumulated end is the normal adjacent case+ /// and must still extend (or hold) the range to that boundary.+ func testTouchingSameSpeakerTurnExtendsToEnd() {+ let merged = SpeakerDiarizationService.mergeAdjacentTurns([+ self.turn("Speaker 1", 0, 10),+ self.turn("Speaker 1", 9.5, 12),+ ])+ XCTAssertEqual(merged.count, 1)+ XCTAssertEqual(merged[0].endSeconds, 12)+ }+func testOverlongRunIsCappedNotMergedIndefinitely() {var turns: [Turn] = []var t = 0.0