知了 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
feat(windows): when an AI service has trouble, the notes window says in one line what is waiting and what still works, with Use Ling one click away
wquguru9f31a5385caa
diff --git a/windows/scripts/cicadactl.ps1 b/windows/scripts/cicadactl.ps1index e2caf43..17a8748 100644--- a/windows/scripts/cicadactl.ps1+++ b/windows/scripts/cicadactl.ps1@@ -1,6 +1,6 @@# Sends one debug command to a running dev build (Cicada.exe --dev) and prints its JSON state.# .\cicadactl.ps1 state | start | stop | end | notesproblem failed | sample | feed C:\clip.wav | view subtitles | capture on | show records | hide notes | quit-# AI 服务: provider ling|openrouter|zenmux|custom | ai-model hear|text|voice <id> | show settings ai models+# AI 服务: provider ling|openrouter|zenmux|custom | switchtoling (a status line's 改用 Ling) | ai-model hear|text|voice <id> | show settings ai models# AI 服务检查: ai-check | ai-check-sim <unreachable|invalidKey|noCredit|mgmtKey|noModel|noJSON|deaf|busy|serverError|lowBalance|off> (state › ai.check: every step)# 结束会议: calls zoom.exe=Zoom|none|real | realcalls | endtimes <silence> <countdown> <grace>|off | endkeepparam([Parameter(ValueFromRemainingArguments = $true)][string[]]$Command)diff --git a/windows/src/Cicada.Core/Ling.cs b/windows/src/Cicada.Core/Ling.csindex b307f7b..bce5f3e 100644--- a/windows/src/Cicada.Core/Ling.cs+++ b/windows/src/Cicada.Core/Ling.cs@@ -35,9 +35,13 @@ public sealed class AIKey(IKeyProtector protector, string? file = null, Func<strreadonly Dictionary<string, string?> cache = [];readonly object gate = new();- public string? Read()+ public string? Read() => ReadAt(File_);++ /// Another service's saved key, without switching to it (改用 Ling asks whether Ling has one).+ public string? Read(string service) => file is null ? ReadAt(Paths.KeyFile(service)) : null;++ string? ReadAt(string path){- var path = File_;lock (gate){if (cache.TryGetValue(path, out var cached)) return cached;diff --git a/windows/src/Cicada.Core/ListenEngine.cs b/windows/src/Cicada.Core/ListenEngine.csindex f6dae7c..1e4ece6 100644--- a/windows/src/Cicada.Core/ListenEngine.cs+++ b/windows/src/Cicada.Core/ListenEngine.cs@@ -70,7 +70,8 @@ public sealed class ListenEngineLingException.Kind.RateLimited => ling ?(Strings.L("Ling 太忙"), Strings.L("稍后会自动重试。"), false) : (null, Strings.LF("%@ 太忙,稍后再试", service), false),LingException.Kind.InvalidKey => (ling ? Strings.L("Ling key 无效") : Strings.LF("%@ 的 key 无效", service), Strings.L("去设置里换一个 key。"), true),LingException.Kind.NoKey => (ling ? Strings.L("Ling key 无效") : Strings.LF("需要 %@ 的 key 才能听", service), Strings.L("去设置里换一个 key。"), true),- _ => (ling ? Strings.L("连不上 Ling") : Strings.LF("连不上 %@", service), Strings.L("这段时间的话没能识别。网络恢复后自动继续。"), false),+ // The service hears the meeting here, so the subtitles wait with the notes.+ _ => (null, Strings.LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", service), false),};}diff --git a/windows/src/Cicada.Core/Speak.cs b/windows/src/Cicada.Core/Speak.csindex 831a6e8..c1ee89b 100644--- a/windows/src/Cicada.Core/Speak.cs+++ b/windows/src/Cicada.Core/Speak.cs@@ -148,13 +148,13 @@ public sealed class SpeakEngineChanged?.Invoke();Heard? heard = null;try { heard = await translator.Hear(wav, to, MyLanguage, Priority.Speak); }- catch (LingException e) { Log.Debug($"speak: hear failed {e.Message}"); return Fail(e.Failure is LingException.Kind.Network or LingException.Kind.Timeout ? (ling.Config.IsLing ? Strings.L("连不上 Ling,没有发出去") : Strings.LF("连不上 %@,没有发出去", ling.Config.Name)) : Strings.L("没翻译成功,没有发出去")); }+ catch (LingException e) { Log.Debug($"speak: hear failed {e.Message}"); return Fail(e.Failure is LingException.Kind.Network or LingException.Kind.Timeout ? (ling.Config.IsLing ? Strings.L("连不上 Ling,没有发出去") : Strings.LF("连不上 %@,没有发出去", ling.Config.Name)) : Strings.L("这句没翻译成 · 没有说出去")); }if (heard is null) return Fail(Strings.L("没听清,没有发出去"));Said = heard.Original;var text = heard.Translation;// Ming didn't translate it: the text translator gets one try; failing that, silence.if (text is null && heard.Lang != to) text = await translator.Translate(heard.Original, heard.Lang, to, Translator.Kind.Sentence, Priority.Speak);- if (string.IsNullOrWhiteSpace(text)) return Fail(Strings.L("没翻译成功,没有发出去"));+ if (string.IsNullOrWhiteSpace(text)) return Fail(Strings.L("这句没翻译成 · 没有说出去"));var translatedAt = DateTime.UtcNow;Heard = text;State = Phase.Speaking;diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 4936dcd..1631c18 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -920,6 +920,17 @@ sealed class ControllerAIChanged();}+ /// "改用 Ling" where another service is out of reach: only when a Ling key is already saved,+ /// so the one click works without a trip to the settings.+ public bool CanSwitchToLing => Settings.AiProvider != "ling" && Key.Read("ling") is not null;++ public void SwitchToLing()+ {+ if (!CanSwitchToLing) return;+ Log.Debug("ai: switched to Ling from the status line");+ SetAIProvider("ling");+ }+/// What the tray says first when the AI service needs the user (title, detail); null otherwise./// On Windows the service hears too, so a dead service means no subtitles either.public (string Title, string Detail)? AIProblem()@@ -1233,6 +1244,8 @@ static class DebugServerelse _ = app.Speak.Speak(Wav.Bytes(Wav.Read(arg)), new DeviceSpeaker(Endpoints.Cable));break;case "provider": app.SetAIProvider(arg); break;+ // switchtoling: the 改用 Ling on a status line (logs why when it isn't offered).+ case "switchtoling": Log.Debug($"switchtoling offered={app.CanSwitchToLing}"); app.SwitchToLing(); break;case "ai-check":// ai-check: a check now; ai-check-sim <reason|lowBalance|off>: every check ends this way (screenshots)._ = app.Ling.Check();diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex 5aa0981..40390c9 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -182,7 +182,7 @@ sealed class NotesWindow : Windowif (Subtitles) { live.Content = SubtitleLine(); return; }var ek = !app.Listen.Listening ? null : app.ConfirmingEnd ? "confirm" : app.Ending is { } p ? p.Reason.ToString() : app.OnlinePrompt is { } o ? "online " + o : null;if (ek != endingKey) { endingKey = ek; ending.Content = EndingStrip(); }- var bk = $"{app.Listen.Problem}|{(app.Listen.Listening && app.Notes.Status is NotesEngine.State.Failed or NotesEngine.State.RateLimited or NotesEngine.State.Unreachable ? app.Notes.Status : null)}|{app.Ling.Health.Failure?.Why}|{app.Ling.Health.Proxy}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";+ var bk = $"{app.Listen.Problem}|{app.Listen.ProblemStatus}|{(app.Listen.Listening && app.Notes.Status is NotesEngine.State.Failed or NotesEngine.State.RateLimited or NotesEngine.State.Unreachable or NotesEngine.State.Updating ? app.Notes.Status : null)}|{app.Ling.Health.Failure?.Why}|{app.Settings.AiProvider}|{app.CanSwitchToLing}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";if (bk != barsKey) { barsKey = bk; bars.Content = Bars(); }live.Content = LiveCard();var count = app.Listen.SessionId is { } sid ? app.Store.Get(sid)?.Lines.Count ?? 0 : 0;@@ -268,41 +268,50 @@ sealed class NotesWindow : Window{var stack = new StackPanel { Margin = new Thickness(12, 0, 12, 0) };void Add(FrameworkElement bar) { bar.Margin = new Thickness(0, 0, 0, 8); stack.Children.Add(bar); }- if (app.Listen.Problem is { } problem)+ // AI trouble is one status line each (NotesWindow.swift › banner): a dot, what waits for+ // what · what still works, at most one action. The service hears the meeting here, so its+ // failing stops the subtitles as well: hearing's line comes first and the notes' own lines+ // only add what it doesn't already say.+ (string, Action)? useLing = app.CanSwitchToLing ? (L("改用 Ling"), app.SwitchToLing) : null;+ var problem = app.Listen.Problem;+ if (problem is { } p){var ling = app.Ling;- var (title, body, settings) = ListenEngine.Words(problem, app.Listen.ProblemStatus, ling.Config.Name, ling.HearName);- // Can't reach it: what this computer's proxy looks like says what to do.- var offline = problem is LingException.Kind.Network or LingException.Kind.Timeout;- if (offline && ling.Health.ProxyLine(ling.ServiceName, ling.ServiceHost) is { } proxy) body += "\n" + proxy;+ var (title, body, settings) = ListenEngine.Words(p, app.Listen.ProblemStatus, ling.Config.Name, ling.HearName);+ var text = (title is null ? body : title.TrimEnd('。', '.') + " · " + body).TrimEnd('。', '.');+ // Can't reach it: picks up by itself once it answers; the proxy hint is in 设置 › AI 服务.+ if (p is LingException.Kind.Network or LingException.Kind.Timeout) Add(Ui.StatusLine(Ui.Tone.Waiting, text, useLing));// Busy or erring (a 5xx): it passes by itself, nothing to press.- if (problem == LingException.Kind.RateLimited || ListenEngine.IsServerError(problem, app.Listen.ProblemStatus)) Add(Ui.InfoBar(Ui.Severity.Warning, title, body));- else if (settings || offline) Add(Ui.InfoBar(Ui.Severity.Error, title, body, Ui.Button(L("设置"), app.ShowAISettings, height: 32)));- else Add(Ui.InfoBar(Ui.Severity.Error, title, body, Ui.Button(L("重试"), () => { app.Listen.ClearProblem(); _ = app.Ling.Check(); }, height: 32)));+ else if (p == LingException.Kind.RateLimited || ListenEngine.IsServerError(p, app.Listen.ProblemStatus)) Add(Ui.StatusLine(Ui.Tone.Waiting, text));+ else if (settings) Add(Ui.StatusLine(Ui.Tone.NeedsYou, text, (p is LingException.Kind.InvalidKey or LingException.Kind.NoKey ? L("换 key") : L("设置"), app.ShowAISettings)));+ // Anything else (a garbled reply, Ling's 400) also picks up by itself; 重试 asks now.+ else Add(Ui.StatusLine(Ui.Tone.Waiting, text, (L("重试"), () => { app.Listen.ClearProblem(); _ = app.Ling.Check(); })));}- // The notes' own trouble (NotesWindow.swift › banner): the last round didn't land.+ var unreachable = app.Ling.Health.Failure?.Why == AICheck.Reason.Unreachable;if (app.Listen.Listening)switch (app.Notes.Status){- case NotesEngine.State.RateLimited:- Add(Ui.InfoBar(Ui.Severity.Warning, null, LF("%@ 很忙,纪要稍后补上。字幕照常。", ServiceLabel())));+ // Hearing goes ahead of the notes, so it is usually still fine: unless its line says otherwise.+ case NotesEngine.State.RateLimited when problem is null:+ Add(Ui.StatusLine(Ui.Tone.Waiting, LF("%@ 很忙 · 纪要稍后补上,字幕照常", ServiceLabel())));break;- // The network or the proxy, not the notes: say which, and that it picks up by itself.// Both: the notes' own request failed, and the service doesn't answer anything; notes that- // only timed out while translations still came back retry on the next round.- // (When hearing failed too, its bar above says so already.)- case NotesEngine.State.Unreachable when app.Ling.Health.Failure?.Why == AICheck.Reason.Unreachable:- if (app.Listen.Problem is not (LingException.Kind.Network or LingException.Kind.Timeout))+ // only timed out while translations still came back retry on the next round. The retry+ // that follows (Updating) hangs as long as a timeout: the line stays meanwhile. When+ // hearing can't reach it either, its line above says so already.+ case NotesEngine.State.Unreachable or NotesEngine.State.Updating when unreachable:+ if (problem is not (LingException.Kind.Network or LingException.Kind.Timeout)){+ // A hear model served at another address still brings subtitles.var until = NotesCoveredUntil();- Add(Ui.InfoBar(Ui.Severity.Error, null,- until > 0 ? LF("连不上 %@,纪要暂停在 %@,连上后自动继续。", ServiceLabel(), Languages.Clock(until))- : LF("连不上 %@,连上后开始写纪要。", ServiceLabel()),- Ui.Button(L("设置"), app.ShowAISettings, height: 32)));+ var text = !app.Ling.Config.HearElsewhere ? LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", ServiceLabel())+ : until > 0 ? LF("纪要等 %@ 恢复 · 停在 %@,字幕照常", ServiceLabel(), Languages.Clock(until))+ : LF("纪要等 %@ 恢复 · 字幕照常", ServiceLabel());+ Add(Ui.StatusLine(Ui.Tone.Waiting, text, useLing));}break;case NotesEngine.State.Failed:- Add(Ui.InfoBar(Ui.Severity.Warning, null, L("这轮没整理好,下一轮会自动重试。")));+ Add(Ui.StatusLine(Ui.Tone.Info, L("这轮纪要没写好 · 下轮自动补上")));break;}// Shown to others on purpose: the footer's 对方可见 says so. Not hidden though asked: a warning.diff --git a/windows/src/Cicada/Onboarding.cs b/windows/src/Cicada/Onboarding.csindex a39c9eb..46f29d7 100644--- a/windows/src/Cicada/Onboarding.cs+++ b/windows/src/Cicada/Onboarding.cs@@ -586,7 +586,7 @@ sealed class Onboarding : WindowSpeakEngine.Phase.Recording => Ui.Text(L("正在听你说 · 松开发送"), 13, Palette.AccentText),SpeakEngine.Phase.Translating => Ui.Text(L("正在翻译…"), 13, Palette.Secondary),SpeakEngine.Phase.Speaking => Ui.Text(L("正在说给对方听…"), 13, Palette.Secondary),- SpeakEngine.Phase.Failed => Ui.Text(app.Speak.Problem ?? L("没翻译成功,没有发出去"), 13, Palette.Danger),+ SpeakEngine.Phase.Failed => Ui.Text(app.Speak.Problem ?? L("这句没翻译成 · 没有说出去"), 13, Palette.Danger),_ when app.Speak.Heard is { } h => Tick(L("对方已听到") + ":" + h),_ => new Border(),};diff --git a/windows/src/Cicada/SpeakBar.cs b/windows/src/Cicada/SpeakBar.csindex ec09c10..2b0deb3 100644--- a/windows/src/Cicada/SpeakBar.cs+++ b/windows/src/Cicada/SpeakBar.cs@@ -61,7 +61,7 @@ sealed class SpeakBar : Windowif (s.State == SpeakEngine.Phase.Idle) hide.Start();break;case SpeakEngine.Phase.Failed:- var why = Ui.Text(s.Problem ?? L("没翻译成功,没有发出去"), 14, new SolidColorBrush(Color.FromRgb(0xFF, 0x9B, 0x78)), FontWeights.Bold);+ var why = Ui.Text(s.Problem ?? L("这句没翻译成 · 没有说出去"), 14, new SolidColorBrush(Color.FromRgb(0xFF, 0x9B, 0x78)), FontWeights.Bold);why.MaxWidth = 480;content = Ui.Row(12, Key(false), why);hide.Start();diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.stringsindex 8348b40..bac4c2f 100644--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings@@ -85,7 +85,6 @@"没找到麦克风" = "No microphone found";"没有声音?先确认电脑没静音" = "No sound? Make sure your PC isn't muted.";"没有找到" = "No results found";-"没翻译成功,没有发出去" = "Couldn't translate. Nothing was sent.";"没能发出声音" = "Couldn't play audio";"清空就用纪要起的名字:%@" = "Leave blank to use the title from notes: %@";"点“开始听”,电脑里播放的声音会变成双语字幕和纪要" = "Select \"Start listening\" to turn your PC's audio into live bilingual subtitles and meeting notes.";diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.stringsindex ee96609..1d4db6b 100644--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings@@ -85,7 +85,6 @@"没找到麦克风" = "マイクが見つかりません";"没有声音?先确认电脑没静音" = "音が聞こえない場合は、PC がミュートになっていないか確認してください";"没有找到" = "見つかりませんでした";-"没翻译成功,没有发出去" = "翻訳できなかったため、送信されませんでした";"没能发出声音" = "音声を出力できませんでした";"清空就用纪要起的名字:%@" = "空欄にするとメモのタイトルが使われます:%@";"点“开始听”,电脑里播放的声音会变成双语字幕和纪要" = "「聞き取り開始」をクリックすると、PC で再生中の音声が 2 か国語の字幕とメモになります。";diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.stringsindex a771ce1..0e84133 100644--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings@@ -85,7 +85,6 @@"没找到麦克风" = "마이크를 찾을 수 없습니다";"没有声音?先确认电脑没静音" = "소리가 안 나나요? 먼저 PC가 음소거 상태인지 확인하세요";"没有找到" = "결과 없음";-"没翻译成功,没有发出去" = "번역하지 못해 전송하지 않았습니다";"没能发出声音" = "소리를 재생하지 못했습니다";"清空就用纪要起的名字:%@" = "비워 두면 회의록에서 생성된 제목을 사용합니다: %@";"点“开始听”,电脑里播放的声音会变成双语字幕和纪要" = "'듣기 시작'을 클릭하면 PC에서 재생되는 소리가 실시간 이중 언어 자막과 회의록으로 변환됩니다.";diff --git a/windows/src/Cicada/Ui.cs b/windows/src/Cicada/Ui.csindex d34bc2f..55e34c3 100644--- a/windows/src/Cicada/Ui.cs+++ b/windows/src/Cicada/Ui.cs@@ -361,6 +361,47 @@ static class Ui};}+ public enum Tone { Waiting, NeedsYou, Info }++ /// #C98A00: WarnIcon is too dark to tell from the text at 6 px.+ static readonly SolidColorBrush waitingDot = Frozen(Color.FromRgb(0xC9, 0x8A, 0x00));+ static SolidColorBrush Frozen(Color c) { var b = new SolidColorBrush(c); b.Freeze(); return b; }++ /// A service in trouble, said the same way wherever it shows (Views.swift › StatusLine): a dot,+ /// what waits for what · what still works, and at most one action. Colour sits in the dot only,+ /// so a passing wait doesn't read as a fault: yellow waits and comes back by itself, red needs+ /// you, grey is just so you know.+ public static Border StatusLine(Tone tone, string text, (string Title, Action Run)? action = null)+ {+ var dot = Dot(tone switch { Tone.Waiting => waitingDot, Tone.NeedsYou => Palette.Danger, _ => Palette.Tertiary }, 6);+ dot.Margin = new Thickness(0, 0, 8, 0);+ var dock = new DockPanel();+ DockPanel.SetDock(dot, Dock.Left);+ dock.Children.Add(dot);+ if (action is { } a)+ {+ var label = Text(a.Title, 12, Palette.Ink, FontWeights.SemiBold, wrap: false);+ var b = new Button+ {+ Content = label, Background = Brushes.Transparent, BorderThickness = new Thickness(0), Cursor = Cursors.Hand,+ Padding = new Thickness(6, 4, 6, 4), Margin = new Thickness(8, 0, -6, 0), VerticalAlignment = VerticalAlignment.Center,+ };+ b.Template = Template(plain: true, radius: 6);+ b.Click += (_, _) => a.Run();+ AutomationName(b, a.Title);+ DockPanel.SetDock(b, Dock.Right);+ dock.Children.Add(b);+ }+ var words = Text(text, 12, Palette.Secondary);+ words.VerticalAlignment = VerticalAlignment.Center;+ dock.Children.Add(words);+ return new Border+ {+ Background = Palette.Subtle, CornerRadius = new CornerRadius(10), Padding = new Thickness(12, 7, 12, 7),+ MinHeight = 36, Child = dock,+ };+ }+/// The Mac's switch: an ink track when on, a grey one when off, a white knob; no 开/关 beside it.public static FrameworkElement Switch(bool on, Action<bool> changed, string name){diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 70b5fca..082c1ab 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -2195,8 +2195,9 @@ static class Testspublic static void ProblemsNameTheService(){Check(ListenEngine.Words(LingException.Kind.Http, 400, "ZenMux").Settings, "a hear model that refuses audio is fixed in settings");- Check(ListenEngine.Words(LingException.Kind.Network, 0, "ZenMux").Title!.Contains("ZenMux"), "named");- Equal("连不上 Ling", ListenEngine.Words(LingException.Kind.Timeout, 0, "Ling").Title, "Ling keeps its words");+ Check(ListenEngine.Words(LingException.Kind.Network, 0, "ZenMux").Body.Contains("ZenMux"), "named");+ // One status line: subtitles and notes both wait, since the service hears the meeting here.+ Equal((null, "字幕和纪要等 Ling 恢复 · 连上后自动继续", false), ListenEngine.Words(LingException.Kind.Timeout, 0, "Ling"), "unreachable is one line");Check(!ListenEngine.Words(LingException.Kind.Http, 400, "Ling").Settings, "Ling's 400 is the network bar");// A gateway's 502 in front of the server: the service erring, not the network, nothing in settings.Equal((null, "ZenMux 暂时出错(HTTP 502),稍后再试。", false), ListenEngine.Words(LingException.Kind.Http, 502, "ZenMux"), "a 5xx is the service's trouble");