知了 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(windows): a meeting record whose misheard words were fixed on the Mac shows the fixed words on Windows and keeps the fixes when saved
wqugurue588aa0a33f4
diff --git a/site/changelog.json b/site/changelog.jsonindex 61905c3..5716610 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -77,6 +77,14 @@],"title": "Android 设置里多了“词表”:常用的人名、产品名一次贴进来,写法和听错的形式都能就地改。","text": "一行一个,常被听错的写法写在 = 后面(Morpho = 莫拉),导入前先显示会新增几个。会中答“对”的词也会记进来,标着“会中确认”和改过几次;删掉的词可以撤销。词表只存在这台手机上。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "windows"+ ],+ "title": "在 Mac 上改过听错的词的会议记录,Windows 版也显示改后的文字,再保存也不会丢掉这些改动。",+ "text": "会议记录里每句仍留着原来听到的话,另记一份改了哪些词。Windows 版的文字记录、搜索、导出和纪要现在都用改后的文字,保存记录时把这份改动原样写回。"}]},diff --git a/windows/src/Cicada.Core/Correction.cs b/windows/src/Cicada.Core/Correction.csnew file mode 100644index 0000000..6774502--- /dev/null+++ b/windows/src/Cicada.Core/Correction.cs@@ -0,0 +1,27 @@+namespace Cicada;++/// 改正听错的词: which of the AI service's proposed fixes a line takes, and the line as shown once+/// they are in. The Mac's Correction.swift, rule for rule.+public static class Correction+{+ /// The line as shown: each applied fix replaces its words where they still are. The marks are+ /// the replaced words (start, length in the shown text), for the dotted underline.+ public static (string Text, List<(int Start, int Length)> Marks) Apply(IReadOnlyList<LineFix> fixes, string src)+ {+ var text = src;+ var spans = new List<(string Word, int At)>();+ // The user's own last: written against the line as it was shown, other fixes in.+ foreach (var f in fixes.Where(f => f.User != true).Concat(fixes.Where(f => f.User == true)))+ {+ if (!f.Applied || f.From.Length == 0) continue;+ var at = text.IndexOf(f.From, StringComparison.Ordinal);+ if (at < 0) continue;+ var delta = f.To.Length - f.From.Length;+ for (int k = 0; k < spans.Count; k++) if (spans[k].At > at) spans[k] = (spans[k].Word, spans[k].At + delta);+ text = text[..at] + f.To + text[(at + f.From.Length)..];+ spans.Add((f.To, at));+ }+ var marks = spans.Where(s => s.At + s.Word.Length <= text.Length).Select(s => (s.At, s.Word.Length)).OrderBy(m => m.Item1).ToList();+ return (text, marks);+ }+}diff --git a/windows/src/Cicada.Core/Models.cs b/windows/src/Cicada.Core/Models.csindex 90056ab..cd55051 100644--- a/windows/src/Cicada.Core/Models.cs+++ b/windows/src/Cicada.Core/Models.cs@@ -10,6 +10,8 @@ public sealed class TranscriptLine{[JsonPropertyName("dst")] public string? Dst { get; set; }[JsonPropertyName("dstLang")] public string DstLang { get; set; } = "";+ /// Words the AI service fixed (Correction); `src` stays what was heard. Absent when none.+ [JsonPropertyName("fixes")] public List<LineFix>? Fixes { get; set; }/// "h<n>-<segment>" for heard lines, "m<n>" for the user's own.[JsonPropertyName("id")] public string Id { get; set; } = "";/// "them" (system audio) or "me" (microphone).@@ -23,9 +25,35 @@ public sealed class TranscriptLine/// Experimental voice id on the Mac; Windows doesn't tell voices apart yet.[JsonPropertyName("voice")] public int? Voice { get; set; }+ /// What the line says once its fixes are in: shown, searched, exported and read by the notes.+ [JsonIgnore] public string Shown => Fixes is { Count: > 0 } f ? Correction.Apply(f, Src).Text : Src;++ /// Shallow: Fixes is shared, so it is only ever replaced with a new list, never changed in place.public TranscriptLine Copy() => (TranscriptLine)MemberwiseClone();}+/// A word the AI service said speech recognition got wrong in a finished line ("莫拉" → "Morpho"),+/// field for field the Mac's LineFix. The flags are written only when true, as Swift leaves out nil.+public sealed record LineFix+{+ /// Waiting for the user (a name sound can't check): not applied until confirmed.+ [JsonPropertyName("ask")] public bool? Ask { get; init; }+ [JsonPropertyName("from")] public string From { get; init; } = "";+ /// The user said no (改回 or 不对): kept so the same line isn't fixed that way again.+ [JsonPropertyName("off")] public bool? Off { get; init; }+ [JsonPropertyName("to")] public string To { get; init; } = "";+ /// The user's own: said 对, or wrote it (改这句…). A later pass never drops or overrides it.+ [JsonPropertyName("user")] public bool? User { get; init; }++ public LineFix() { }+ public LineFix(string from, string to, bool ask = false, bool off = false, bool user = false)+ {+ From = from; To = to; Ask = ask ? true : null; Off = off ? true : null; User = user ? true : null;+ }++ [JsonIgnore] public bool Applied => Ask != true && Off != true;+}+public sealed class VoiceGuess{[JsonPropertyName("evidence")] public string Evidence { get; set; } = "";diff --git a/windows/src/Cicada.Core/Notes.cs b/windows/src/Cicada.Core/Notes.csindex 5925b78..b7a9e44 100644--- a/windows/src/Cicada.Core/Notes.cs+++ b/windows/src/Cicada.Core/Notes.cs@@ -370,7 +370,7 @@ public sealed class NotesEngine// As Notes.swift: a named voice as its name, else 说话人N once voices are told apart,// 未识别 for a voice not on show.var who = l.Speaker == "me" ? "你" : numbers.TryGetValue(l.Id, out var n) ? names?.GetValueOrDefault(n) ?? $"说话人{n}" : numbers.Count == 0 ? "对方" : "未识别";- return $"[L{i + 1} {Languages.Clock(l.T)} {who}] {l.Src}";+ return $"[L{i + 1} {Languages.Clock(l.T)} {who}] {l.Shown}";}var current = notes.IsEmpty ? "{}" : CompactJson(notes, frozen);int context = Math.Max(0, from - 2);diff --git a/windows/src/Cicada.Core/SessionStore.cs b/windows/src/Cicada.Core/SessionStore.csindex e025b56..b0f49b4 100644--- a/windows/src/Cicada.Core/SessionStore.cs+++ b/windows/src/Cicada.Core/SessionStore.cs@@ -95,11 +95,27 @@ public sealed class SessionStoreint i = s.Lines.FindIndex(l => l.Id == line.Id);if (i < 0) return;grew = line.Src.Length > s.Lines[i].Src.Length; // a half sentence joined, not a retranslation+ // The listening engine keeps its own copy of the line and knows nothing of its fixes+ // (SetFixes): a retranslation or a join keeps them.+ line.Fixes ??= s.Lines[i].Fixes;s.Lines[i] = line;});if (grew) Words?.Invoke(id);}+ /// A line's fixes (Correction): what the AI service proposed and the user decided.+ public void SetFixes(string id, string lineId, IReadOnlyList<LineFix> fixes)+ {+ Mutate(id, s =>+ {+ int i = s.Lines.FindIndex(l => l.Id == lineId);+ if (i < 0) return;+ var line = s.Lines[i].Copy();+ line.Fixes = fixes.Count == 0 ? null : [.. fixes];+ s.Lines[i] = line;+ });+ }+public void SetNotes(string id, MeetingNotes notes) => Mutate(id, s => s.Notes = notes);/// Heard through a microphone in the room for some or all of it (SessionStore.swift › markLiveInRoom).@@ -249,8 +265,8 @@ public sealed class SessionStore{// Your own lines (the talk key) say so: what the meeting heard was their translation (同传).var who = l.Speaker == "me" ? Strings.L("你 · 同传") : numbers.TryGetValue(l.Id, out var num) ? names.GetValueOrDefault(num) ?? Strings.LF("说话人 %lld", num) : null;- b.AppendLine($"**{Languages.Clock(l.T)}**{(who is null ? "" : $" {who}:")} {l.Src} ");- if (!string.IsNullOrEmpty(l.Dst) && l.Dst != l.Src) b.AppendLine($"{l.Dst}");+ b.AppendLine($"**{Languages.Clock(l.T)}**{(who is null ? "" : $" {who}:")} {l.Shown} ");+ if (!string.IsNullOrEmpty(l.Dst) && l.Dst != l.Src && l.Dst != l.Shown) b.AppendLine($"{l.Dst}");b.AppendLine();}return b.ToString();diff --git a/windows/src/Cicada/MainWindow.cs b/windows/src/Cicada/MainWindow.csindex cf72754..9655ffe 100644--- a/windows/src/Cicada/MainWindow.cs+++ b/windows/src/Cicada/MainWindow.cs@@ -136,7 +136,7 @@ sealed class MainWindow : Windowq.Length == 0|| SessionStore.DisplayTitle(s).Contains(q, StringComparison.OrdinalIgnoreCase)|| (s.Notes?.Summary.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false)- || s.Lines.Any(l => l.Src.Contains(q, StringComparison.OrdinalIgnoreCase) || (l.Dst?.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false));+ || s.Lines.Any(l => l.Shown.Contains(q, StringComparison.OrdinalIgnoreCase) || (l.Dst?.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false));void Fill(){diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex 891d2ad..d09c399 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -382,8 +382,8 @@ sealed class NotesWindow : Windowvar whoRow = Ui.Row(8, Ui.Text(who, 12, NightAccent, wrap: false));whoRow.Children.Add(Gap(Ui.Text(listen.Listening && listen.Pending > 0 ? L("正在说") : Languages.Clock(line.T), 12, Palette.NightText, wrap: false), 8));stack.Children.Add(whoRow);- if (line.Dst is not null && line.Dst != line.Src) stack.Children.Add(Gap(Ui.Text(line.Src, 13, NightBody), 6, top: true));- stack.Children.Add(Gap(Ui.Text(line.Dst ?? line.Src, 16, Brushes.White, FontWeights.Bold), 6, top: true));+ if (line.Dst is not null && line.Dst != line.Src) stack.Children.Add(Gap(Ui.Text(line.Shown, 13, NightBody), 6, top: true));+ stack.Children.Add(Gap(Ui.Text(line.Dst ?? line.Shown, 16, Brushes.White, FontWeights.Bold), 6, top: true));}return new Border { Background = Palette.Night, CornerRadius = new CornerRadius(14), Padding = new Thickness(16, 14, 16, 14), Child = stack, MinHeight = 96 };}@@ -617,8 +617,8 @@ sealed class NotesWindow : Windowif (who is not null) head.Children.Insert(0, l.Speaker == "me" ? MeTag(who, ink) : Ui.Text(who, 12, ink ?? Palette.Secondary, wrap: false));for (int i = 1; i < head.Children.Count; i++) ((FrameworkElement)head.Children[i]).Margin = new Thickness(i == 1 && place && who is not null ? 6 : 8, 0, 0, 0);text.Children.Add(head);- var translated = !string.IsNullOrEmpty(l.Dst) && l.Dst != l.Src;- text.Children.Add(Gap(Ui.Text(l.Src, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), 3, top: true));+ var translated = !string.IsNullOrEmpty(l.Dst) && l.Dst != l.Src && l.Dst != l.Shown;+ text.Children.Add(Gap(Ui.Text(l.Shown, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), 3, top: true));if (translated) text.Children.Add(Gap(Ui.Text(l.Dst!, 15, Palette.Ink), 2, top: true));return text;}@@ -714,9 +714,9 @@ sealed class NotesWindow : Windowvar who = line.Speaker == "me" ? L("你 · 同传") : number is { } k ? LF("说话人 %lld", k) : null;var top = new TextBlock { FontFamily = Palette.Font, FontSize = 13, TextTrimming = TextTrimming.CharacterEllipsis, Foreground = Palette.NightText };if (who is not null) top.Inlines.Add(new System.Windows.Documents.Run(who + " ") { Foreground = NightAccent });- if (line.Dst is not null && line.Dst != line.Src) top.Inlines.Add(new System.Windows.Documents.Run(line.Src));+ if (line.Dst is not null && line.Dst != line.Src) top.Inlines.Add(new System.Windows.Documents.Run(line.Shown));if (top.Inlines.Count > 0) text.Children.Add(top);- text.Children.Add(Gap(Ui.Text(line.Dst ?? line.Src, app.Settings.SubtitleSize, Brushes.White, FontWeights.Bold), 4, top: true));+ text.Children.Add(Gap(Ui.Text(line.Dst ?? line.Shown, app.Settings.SubtitleSize, Brushes.White, FontWeights.Bold), 4, top: true));}return text;}diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex b6d3b8b..1e5a3fb 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -271,6 +271,68 @@ static class TestsCheck(JsonNode.DeepEquals(JsonNode.Parse(mac), JsonNode.Parse(Json.Write(s))), "written back unchanged");}+ /// 改正听错的词: a Mac record whose lines carry fixes reads and writes back byte for byte in+ /// value, and the line shows (and exports) the fixed words while `src` stays what was heard.+ public static void KeepsTheMacsFixes()+ {+ const string mac = """+ {+ "hasAudio" : false,+ "id" : "20261107-013000",+ "lines" : [+ {+ "dst" : "Recently Curve raised it; Morpho too.",+ "dstLang" : "en",+ "fixes" : [+ { "ask" : true, "from" : "开布特", "to" : "Curve" },+ { "from" : "莫拉", "to" : "Morpho" },+ { "from" : "质压", "off" : true, "to" : "质押" },+ { "from" : "Morpho", "to" : "Monad", "user" : true }+ ],+ "id" : "h1-1",+ "speaker" : "them",+ "src" : "最近那个开布特提了,莫拉也是,质压",+ "srcLang" : "zh-CN",+ "t" : 1.5+ },+ { "dstLang" : "en", "id" : "h2-2", "speaker" : "them", "src" : "好的", "srcLang" : "zh-CN", "t" : 4 }+ ],+ "startedAt" : "2026-11-07T06:30:00Z",+ "title" : "会议 11月7日 01:30"+ }+ """;+ var s = Json.Read<Session>(mac)!;+ var l = s.Lines[0];+ Equal(4, l.Fixes!.Count, "fixes read");+ Equal(true, l.Fixes[0].Ask, "ask");+ Equal(null, l.Fixes[1].Ask, "absent flags stay null");+ Equal("最近那个开布特提了,Monad也是,质压", l.Shown, "applied fixes in, the user's last; waiting and refused ones out");+ Equal("最近那个开布特提了,莫拉也是,质压", l.Src, "src is what was heard");+ Equal(null, s.Lines[1].Fixes, "a line without fixes");+ Check(JsonNode.DeepEquals(JsonNode.Parse(mac), JsonNode.Parse(Json.Write(s))), "written back unchanged");+ var written = Json.Write(s);+ var keys = JsonNode.Parse(written)!["lines"]![0]!.AsObject().Select(p => p.Key).ToList();+ Check(keys.SequenceEqual(keys.Order(StringComparer.Ordinal)), "line keys sorted with fixes");+ var fixKeys = JsonNode.Parse(written)!["lines"]![0]!["fixes"]![2]!.AsObject().Select(p => p.Key).ToList();+ Equal("from,off,to", string.Join(",", fixKeys), "fix keys sorted, false flags left out");+ Check(!JsonNode.Parse(written)!["lines"]![1]!.AsObject().ContainsKey("fixes"), "no fixes key without fixes");+ Check(SessionStore.Markdown(s).Contains("Monad也是"), "the export uses the shown text");+ Check(!SessionStore.Markdown(s).Contains("莫拉"), "not the heard one");+ }++ public static void ARetranslationKeepsTheLinesFixes()+ {+ var store = new SessionStore();+ var id = store.Begin().Id;+ store.Append(id, new TranscriptLine { Id = "h1-1", Src = "但质压这种", SrcLang = "zh-CN", DstLang = "en" });+ store.SetFixes(id, "h1-1", [new LineFix("质压", "质押")]);+ store.Replace(id, new TranscriptLine { Id = "h1-1", Src = "但质压这种", Dst = "but staking", SrcLang = "zh-CN", DstLang = "en" });+ Equal("但质押这种", store.Get(id)!.Lines[0].Shown, "fixes kept through Replace");+ store.SetFixes(id, "h1-1", []);+ Equal(null, store.Get(id)!.Lines[0].Fixes, "none is absent");+ store.Delete(id);+ }+public static void StoreSavesAndDropsEmptyMeetings(){var store = new SessionStore();