知了 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
chore(windows): rewrite notes when their language changes, drop lone fillers, keep topic starts honest
wquguru4dc0cd7f5e7b
diff --git a/windows/src/Cicada.Core/Notes.cs b/windows/src/Cicada.Core/Notes.csindex 268278d..8d71429 100644--- a/windows/src/Cicada.Core/Notes.cs+++ b/windows/src/Cicada.Core/Notes.cs@@ -19,6 +19,8 @@ public sealed class NotesEnginebool inFlight;string? pendingFinal;DateTime lastAttempt = DateTime.MinValue;+ /// The language the shown notes were last written in.+ string? writtenIn;Timer? timer;public MeetingNotes Notes { get; private set; } = new();@@ -41,7 +43,7 @@ public sealed class NotesEngine{lock (gate){- sessionId = id; ShownId = id;+ sessionId = id; ShownId = id; writtenIn = null;Notes = store.Get(id)?.Notes ?? new MeetingNotes();Status = ling.HasKey ? State.Idle : State.NoKey;lastAttempt = DateTime.UtcNow;@@ -106,8 +108,11 @@ public sealed class NotesEnginetry{var lines = session.Lines.ToList();- int from = final ? 0 : Math.Min(baseNotes.Covered, lines.Count);var lang = Language();+ // The language changed mid-meeting: write the notes again from the start in the new one.+ // (The script check can't tell Chinese from Japanese, so extending them would keep the old.)+ if (!final && writtenIn is not null && writtenIn != lang) { baseNotes = new MeetingNotes(); Log.Debug($"notes: language now {lang}, rewriting"); }+ int from = final ? 0 : Math.Min(baseNotes.Covered, lines.Count);var prompt = Prompt(baseNotes, lines, from, lang, final);MeetingNotes? next = null;for (int attempt = 1; attempt <= (final ? 2 : 1); attempt++)@@ -129,7 +134,7 @@ public sealed class NotesEnginenext.Covered = lines.Count;next.UpdatedAt = DateTimeOffset.Now;next.Final = final;- lock (gate) { if (id == ShownId) Notes = next; }+ lock (gate) { if (id == ShownId) Notes = next; writtenIn = lang; }store.SetNotes(id, next);Status = State.Idle;Log.Debug($"notes: {(final ? "final" : "live")} update {lines.Count - from} new lines -> {next.Topics.Count} topics, {next.Terms.Count} terms");@@ -310,10 +315,12 @@ public sealed class NotesEnginepointTimes.Add(p is JsonObject po2 ? Time(po2["evidence"]) : null);}}- // The model's "start" is sometimes misread (04:49 for 00:49); the lines it cites are not.- // So the earliest cited line wins, and a time past the last line is pulled back to it.+ // The model's "start" is sometimes misread (04:49 for 00:49), and the lines it cites can+ // all be late ones (a rewrite cites what's fresh): a topic starts at the earlier of the two,+ // and never after the last line.var cited = new[] { Time(t["evidence"]) }.Concat(pointTimes).Where(x => x is not null).Select(x => x!.Value).ToList();- var start = cited.Count > 0 ? cited.Min() : Num(t["start"]) ?? startedAt;+ var said = Num(t["start"]);+ var start = cited.Count == 0 ? said ?? startedAt : said is { } x0 ? Math.Min(x0, cited.Min()) : cited.Min();if (times.Count > 0 && start > times[^1]) start = times[^1];n.Topics.Add(new NoteTopic{diff --git a/windows/src/Cicada.Core/Translator.cs b/windows/src/Cicada.Core/Translator.csindex e8110dd..2e0a6df 100644--- a/windows/src/Cicada.Core/Translator.cs+++ b/windows/src/Cicada.Core/Translator.cs@@ -37,6 +37,14 @@ public sealed class Translator(LingClient ling)return ParseHeard(reply, target, hint);}+ static readonly HashSet<string> Fillers = ["嗯", "啊", "呃", "哦", "噢", "唔", "额", "哈", "uh", "um", "umm", "hmm", "mm", "mhm", "ah", "oh", "eh", "えー", "あー", "うん", "ええと", "음", "어"];++ public static bool IsFiller(string text)+ {+ var words = text.ToLowerInvariant().Split([' ', ',', ',', '、', '.', '。', '!', '!', '?', '?', '…', '~', '-'], StringSplitOptions.RemoveEmptyEntries);+ return words.Length > 0 && words.Length <= 3 && words.All(Fillers.Contains);+ }+public static string HearPrompt(string target, string? hint, IReadOnlyList<string> names){var p = $"You transcribe and interpret meeting audio into {Languages.EnglishName(target)}. "@@ -69,6 +77,8 @@ public sealed class Translator(LingClient ling)}if (string.IsNullOrWhiteSpace(original) || original.Trim('.', '。', ' ').Equals("NONE", StringComparison.OrdinalIgnoreCase)) return null;if (!original.Any(char.IsLetterOrDigit)) return null;+ // A system sound or a cough comes back as a lone filler ("嗯。", "Mm."): not a line anyone said.+ if (IsFiller(original)) return null;var code = Languages.Normalize(lang, hint ?? "en");if (code == target) translation = original;else if (translation is not null)diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex fd874a5..04e2dbf 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -138,6 +138,12 @@ static class TestsEqual("ja", Translator.ParseHeard("lang: ja-JP\noriginal: はい\ntranslation: 是", "zh-CN", null)!.Lang, "labels in any case");}+ public static void DropsLoneFillers()+ {+ Check(Translator.IsFiller("嗯。") && Translator.IsFiller("Mm.") && Translator.IsFiller("uh, um"), "fillers");+ Check(!Translator.IsFiller("嗯,好的。") && !Translator.IsFiller("OK.") && !Translator.IsFiller("Oh no, it crashed."), "real lines stay");+ }+public static void NormalizesLanguages(){Equal("zh-CN", Languages.Normalize("zh-Hans", "en"), "zh-Hans");@@ -260,6 +266,8 @@ static class Testsvar n = NotesEngine.Parse(raw, times, 0)!;Equal(49.0, n.Topics[0].Start, "the cited line's time, not the model's 289");Equal(180.0, n.Topics[1].Start, "never after the last line");+ var late = NotesEngine.Parse("{\"summary\":\"s\",\"topics\":[{\"start\":5,\"title\":\"整场\",\"points\":[{\"text\":\"p\",\"evidence\":[\"L4\"]}]}]}", times, 0)!;+ Equal(5.0, late.Topics[0].Start, "a rewrite citing only late lines keeps the model's earlier start");}public static void KeepsEarliestTimes()