知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix: the live notes transcript starts a new paragraph every two or three sentences when someone talks fast
wquguru7c40e6b11301
diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex e87d216..3d14c59 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -846,8 +846,18 @@ extension TranscriptListView {/// The notes window's transcript reads as paragraphs: one person's lines within 30 seconds of the/// paragraph's first are one block, one time, instead of a row and a rule for every fragment.+/// A fast speaker fills 30 seconds with a wall of text (issue #20): a paragraph that has reached+/// `full` takes no more lines.enum TranscriptParagraphs {static let span: Double = 30+ /// Two or three sentences: Chinese or Japanese characters, or words.+ static let full = (cjk: 80, words: 40)++ static func isFull(_ lines: [TranscriptLine]) -> Bool {+ let text = lines.map(\.src).joined(separator: " ")+ let cjk = text.unicodeScalars.contains { $0.properties.isIdeographic || (0x3040...0x30FF).contains($0.value) }+ return cjk ? text.filter(\.isLetter).count >= full.cjk : text.split(whereSeparator: \.isWhitespace).count >= full.words+ }static func group(_ lines: [TranscriptLine], _ speakers: [String: Int]) -> [[TranscriptLine]] {var out: [[TranscriptLine]] = []@@ -859,7 +869,8 @@ enum TranscriptParagraphs {for l in lines {let k = (l.speaker == "me" ? "me" : speakers[l.id].map { "n\($0)" } ?? "?") + (l.via ?? "")let v = speakers.isEmpty && l.speaker == "them" && SpeakerLabels.substantive(l.src) ? l.voice : nil- if k == key, let first = out.last?.first, l.t - first.t <= span, voice == nil || v == nil || v == voice {+ if k == key, let p = out.last, let first = p.first, l.t - first.t <= span, !isFull(p),+ voice == nil || v == nil || v == voice {out[out.count - 1].append(l)voice = voice ?? v} else {diff --git a/Tests/CicadaTests/NotesWindowTests.swift b/Tests/CicadaTests/NotesWindowTests.swiftindex d0446e6..97f43b4 100644--- a/Tests/CicadaTests/NotesWindowTests.swift+++ b/Tests/CicadaTests/NotesWindowTests.swift@@ -33,6 +33,16 @@ import Testing#expect(groups.map { $0.map(\.id) } == [["a", "b", "c"], ["d"], ["e"], ["f"]])}+ @Test func paragraphsStopGrowingOnceFull() {+ // Fast Japanese with no break (issue #20): a few sentences to a paragraph, not 30 s of them.+ let ja = "いつも動画をご覧いただきありがとうございます。今回は新型が届いたので開封していきます。" // 42 letters+ let fast = (0..<6).map { line("j\($0)", Double($0) * 4, "them", ja) }+ #expect(TranscriptParagraphs.group(fast, [:]).map { $0.map(\.id) } == [["j0", "j1"], ["j2", "j3"], ["j4", "j5"]])+ // Ordinary English lines: 30 s still decides.+ let en = (0..<4).map { line("e\($0)", Double($0) * 7, "them", "we should ship the fix this week") }+ #expect(TranscriptParagraphs.group(en, [:]).map(\.count) == [4])+ }+@Test func paragraphsSplitBetweenSpeakers() {let lines = [line("a", 0), line("b", 2), line("c", 4)]let groups = TranscriptParagraphs.group(lines, ["a": 1, "b": 2, "c": 2])