Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix: Generate Notes on a long meeting no longer drops a topic and keeps only its "(continued)" end

wquguru452aaec5c609
diff --git a/Sources/Cicada/Notes.swift b/Sources/Cicada/Notes.swift
index 44921b8..ea88807 100644
--- a/Sources/Cicada/Notes.swift
+++ b/Sources/Cicada/Notes.swift
@@ -355,7 +355,7 @@ final class NotesEngine: ObservableObject {
part["topics"] = nil
guard let data = try? JSONSerialization.data(withJSONObject: part), let text = String(data: data, encoding: .utf8) else { return nil }
notes.append(text)
- topics += Self.spread(parsed.topics, to: Self.partTopics(parts.count))
+ topics += Self.thinned(parsed.topics, to: Self.partTopics(parts.count), end: lines[parts[i].upperBound - 1].t)
}
let voices = TranscriptExport.voices && !SpeakerLabels.numbers(lines).isEmpty
let prompt = Self.mergePrompt(parts: notes, lines: lines, language: lang, voices: voices)
@@ -568,13 +568,32 @@ final class NotesEngine: ObservableObject {
/// Each part's share of the topics: the merge keeps them as they are, so every part has some.
static func partTopics(_ parts: Int) -> Int { max(2, maxTopics / max(1, parts)) }
- /// `count` of `topics`, spread evenly from the first to the last: a part's reply often has more
- /// topics than asked, and keeping the first ones (or folding the rest into the last) lost the
- /// end of each part.
- static func spread(_ topics: [NoteTopic], to count: Int) -> [NoteTopic] {
- guard topics.count > count, count > 0 else { return topics }
- guard count > 1 else { return [topics[0]] }
- return (0..<count).map { topics[Int((Double($0) * Double(topics.count - 1) / Double(count - 1)).rounded())] }
+ /// At most `count` of a part's `topics`, neighbours joined: a part's reply often has more topics
+ /// than asked. Keeping the first ones lost the end of the part, and keeping some spread from first
+ /// to last kept a topic's "(续)" stub at the part's end and dropped the topic itself. The same
+ /// subject twice is joined first, under the first one's title; then the pair spanning the least
+ /// time (to the next topic's start, or `end` for the last), as live notes do.
+ static func thinned(_ topics: [NoteTopic], to count: Int, end: Double) -> [NoteTopic] {
+ var topics = topics
+ while topics.count > max(1, count) {
+ let pairs = 0..<topics.count - 1
+ func span(_ i: Int) -> Double { (i + 2 < topics.count ? topics[i + 2].start : end) - topics[i].start }
+ let same = pairs.first { subject(topics[$0].title) == subject(topics[$0 + 1].title) }
+ let i = same ?? pairs.min { span($0) < span($1) }!
+ var one = joined(topics[i], topics[i + 1])
+ if same != nil { (one.title, one.summary) = (topics[i].title, topics[i].summary) }
+ topics[i] = one
+ topics.remove(at: i + 1)
+ }
+ return topics
+ }
+
+ /// A topic title without a trailing bracket ("预算评审(续)", "Budget (cont.)"): what it is about.
+ static func subject(_ title: String) -> String {
+ let t = title.trimmingCharacters(in: .whitespaces)
+ guard let close = t.last, "))".contains(close), let open = t.lastIndex(where: { "((".contains($0) }),
+ open > t.startIndex else { return t }
+ return t[..<open].trimmingCharacters(in: .whitespaces)
}
/// The whole meeting's title, summary, conclusions, to-dos and terms from its parts' notes (the
diff --git a/Tests/CicadaTests/NotesTests.swift b/Tests/CicadaTests/NotesTests.swift
index 7b3d8a8..29bcb15 100644
--- a/Tests/CicadaTests/NotesTests.swift
+++ b/Tests/CicadaTests/NotesTests.swift
@@ -133,10 +133,28 @@ import Testing
#expect(n?.topics.map(\.start) == [51 * 60, 300])
}
- @Test func partTopicsSpreadOverThePart() {
+ @Test func partTopicsJoinedNotDropped() {
let ten = (0..<10).map { topic(Double($0 * 300), "t\($0)") }
- #expect(NotesEngine.spread(ten, to: 4).map(\.title) == ["t0", "t3", "t6", "t9"])
- #expect(NotesEngine.spread(ten, to: 1).map(\.title) == ["t0"])
- #expect(NotesEngine.spread(Array(ten.prefix(3)), to: 4).count == 3)
+ let four = NotesEngine.thinned(ten, to: 4, end: 3000)
+ #expect(four.count == 4)
+ #expect(four.first?.start == 0)
+ #expect(ten.allSatisfy { t in four.contains { $0.title.components(separatedBy: " / ").contains(t.title) } })
+ #expect(NotesEngine.thinned(ten, to: 1, end: 3000).map(\.start) == [0])
+ #expect(NotesEngine.thinned(Array(ten.prefix(3)), to: 4, end: 3000).count == 3)
+ }
+
+ @Test func partTopicsKeepATopicOverItsContinuation() {
+ // A 2.5-hour meeting's last part, asked for 2 topics, came back with 3: the budget topic's
+ // end as its own. Kept first and last, the budget topic at 125 min was lost.
+ let part = [topic(6000, "营销发布安排", ["a"]), topic(7500, "预算评审", ["b"]), topic(8982, "预算评审(续)", ["c"])]
+ let kept = NotesEngine.thinned(part, to: 2, end: 8990)
+ #expect(kept.map(\.title) == ["营销发布安排", "预算评审"])
+ #expect(kept.map(\.start) == [6000, 7500])
+ #expect(kept[1].points == ["b", "c"])
+ // Told apart by time alone, the stub still joins the topic it ends.
+ let other = [topic(6000, "营销发布安排"), topic(7500, "预算评审"), topic(8982, "收尾")]
+ #expect(NotesEngine.thinned(other, to: 2, end: 8990).map(\.start) == [6000, 7500])
+ #expect(NotesEngine.subject("Budget review (cont.)") == "Budget review")
+ #expect(NotesEngine.subject("(续)") == "(续)")
}
}
diff --git a/site/changelog.json b/site/changelog.json
index 5887d14..9e83f09 100644
--- a/site/changelog.json
+++ b/site/changelog.json
@@ -13,6 +13,14 @@
],
"title": "刚开完会就换 AI 服务,设置里不再把新服务显示成已连接。",
"text": "会议最后一版纪要还在发给原来的服务,它的回复原来会被算到新服务头上。"
+ },
+ {
+ "kind": "fixed",
+ "platforms": [
+ "mac"
+ ],
+ "title": "长会议生成完整纪要时,不再丢掉某个话题、只留下它的“(续)”。",
+ "text": "长会议分几段写纪要,某一段写出的话题比要的多时,原来按位置挑几个留下,可能留下话题末尾单独列出的“(续)”、丢掉话题本身;现在多出的话题并进相邻的话题,同一话题的续篇并回原话题。"
}
]
},