知了 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(linux): Generate Notes on a long meeting no longer drops a topic and keeps only its "(continued)" end
wquguruc3493fc26701
diff --git a/linux/cicada/core/notes.py b/linux/cicada/core/notes.pyindex db822d8..5a454e3 100644--- a/linux/cicada/core/notes.py+++ b/linux/cicada/core/notes.py@@ -263,7 +263,7 @@ class NotesEngine:# Without its topics: given them, the merge wrote them all back out and was cut off.root.pop("topics", None)notes.append(jsonfmt.write(root, pretty=False))- topics += spread(parsed.topics, part_topics(len(ranges)))+ topics += thinned(parsed.topics, part_topics(len(ranges)), lines[ranges[i].stop - 1].t)p = merge_prompt(notes, lines, lang, voices and bool(speakers.numbers(lines)))for attempt in (1, 2):try:@@ -493,16 +493,33 @@ def part_topics(n: int) -> int:return max(2, MAX_TOPICS // max(1, n))-def spread(topics: list, count: int) -> list:- """`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."""- if len(topics) <= count or count <= 0:- return topics- if count == 1:- return [topics[0]]- # Rounded half up, as Swift's rounded() does for these non-negative positions.- return [topics[int(k * (len(topics) - 1) / (count - 1) + 0.5)] for k in range(count)]+def thinned(topics: list, count: int, end: float) -> list:+ """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."""+ topics = list(topics)+ while len(topics) > max(1, count):+ pairs = range(len(topics) - 1)+ same = next((i for i in pairs if subject(topics[i].title) == subject(topics[i + 1].title)), None)+ # min() keeps the first of equal spans, as the Mac does.+ i = same if same is not None else min(+ pairs, key=lambda j: (topics[j + 2].start if j + 2 < len(topics) else end) - topics[j].start)+ one = joined(topics[i], topics[i + 1])+ if same is not None:+ one = replace(one, title=topics[i].title, summary=topics[i].summary)+ topics[i:i + 2] = [one]+ return topics+++def subject(title: str) -> str:+ """A topic title without a trailing bracket ("预算评审(续)", "Budget (cont.)"): what it is about."""+ t = title.strip()+ if not t or t[-1] not in "))":+ return t+ open_at = max(t.rfind("("), t.rfind("("))+ return t[:open_at].strip() if open_at > 0 else tdef merge_prompt(parts: list, lines: list, language: str, voices: bool) -> str:diff --git a/linux/tests/test_core.py b/linux/tests/test_core.pyindex d25bcd4..234a7b5 100644--- a/linux/tests/test_core.py+++ b/linux/tests/test_core.py@@ -724,11 +724,29 @@ class Notes(Base):{"start": 300, "title": "no evidence", "summary": "s", "points": ["c"]}]}"""self.assertEqual([51 * 60, 300], [t.start for t in notesmod.parse(raw, times, 0.0).topics])- def test_part_topics_spread_over_the_part(self):+ def test_part_topics_joined_not_dropped(self):ten = [self._topic(i * 300, "t%d" % i) for i in range(10)]- self.assertEqual(["t0", "t3", "t6", "t9"], [t.title for t in notesmod.spread(ten, 4)])- self.assertEqual(["t0"], [t.title for t in notesmod.spread(ten, 1)])- self.assertEqual(3, len(notesmod.spread(ten[:3], 4)))+ four = notesmod.thinned(ten, 4, 3000)+ self.assertEqual(4, len(four))+ self.assertEqual(0, four[0].start)+ self.assertTrue(all(any(t.title in k.title.split(" / ") for k in four) for t in ten))+ self.assertEqual([0], [t.start for t in notesmod.thinned(ten, 1, 3000)])+ self.assertEqual(3, len(notesmod.thinned(ten[:3], 4, 3000)))++ def test_part_topics_keep_a_topic_over_its_continuation(self):+ # 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.+ part = [self._topic(6000, "营销发布安排", ["a"]), self._topic(7500, "预算评审", ["b"]),+ self._topic(8982, "预算评审(续)", ["c"])]+ kept = notesmod.thinned(part, 2, 8990)+ self.assertEqual(["营销发布安排", "预算评审"], [t.title for t in kept])+ self.assertEqual([6000, 7500], [t.start for t in kept])+ self.assertEqual(["b", "c"], list(kept[1].points))+ # Told apart by time alone, the stub still joins the topic it ends.+ other = [self._topic(6000, "营销发布安排"), self._topic(7500, "预算评审"), self._topic(8982, "收尾")]+ self.assertEqual([6000, 7500], [t.start for t in notesmod.thinned(other, 2, 8990)])+ self.assertEqual("Budget review", notesmod.subject("Budget review (cont.)"))+ self.assertEqual("(续)", notesmod.subject("(续)"))def test_long_final_in_parts_then_merged(self):# Four hours: four part calls at once, then one merge; topics come from the parts.@@ -756,7 +774,8 @@ class Notes(Base):self.assertIn("Part 4 of 4:", asked[-1])self.assertNotIn("话题1-0", asked[-1], "the parts go to the merge without their topics")self.assertEqual("全程讨论", n.summary)- self.assertEqual(["话题%d-%d" % (k, j) for k in range(1, 5) for j in (0, 2)], [t.title for t in n.topics])+ # Three topics a part, two asked for: the pair spanning the least time is joined.+ self.assertEqual([t for k in range(1, 5) for t in ("话题%d-0 / 话题%d-1" % (k, k), "话题%d-2" % k)], [t.title for t in n.topics])self.assertTrue(n.final)def test_notes_prompt_matches_the_android_port(self):diff --git a/site/changelog.json b/site/changelog.jsonindex 1331e84..320ffed 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -18,7 +18,8 @@"kind": "fixed","platforms": ["mac",- "windows"+ "windows",+ "linux"],"title": "长会议生成完整纪要时,不再丢掉某个话题、只留下它的“(续)”。","text": "长会议分几段写纪要,某一段写出的话题比要的多时,原来按位置挑几个留下,可能留下话题末尾单独列出的“(续)”、丢掉话题本身;现在多出的话题并进相邻的话题,同一话题的续篇并回原话题。"