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.

chore(windows): flag a window Windows won't hide from capture, require Windows 10 2004, retry busy Ming calls once

wqugurub8e27bd9d972
diff --git a/docs/windows-plan.md b/docs/windows-plan.md
index 5b6c047..d068ad5 100644
--- a/docs/windows-plan.md
+++ b/docs/windows-plan.md
@@ -47,26 +47,28 @@ WASAPI 进程回环(排除知了自己)
→ SessionStore(session.json + system.m4a)
```
-### 模块(`windows/src/Cicada/`,一个文件一件事,对应 Mac 的文件名)
+### 模块
+
+引擎在 `windows/src/Cicada.Core/`(`net10.0`,Mac 上也能编译和测试),界面在 `windows/src/Cicada/`:
| 文件 | 作用 | 对应 Mac |
|---|---|---|
-| `SystemAudioTap.cs` | `ActivateAudioInterfaceAsync`,用 `PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREE` 排除自己 | `SystemAudioTap.swift` |
-| `FileAudioSource.cs` | 从 WAV 或 m4a 文件喂音频,用于测试和 CI | 无(Mac 用 `afplay` 播放) |
-| `AudioRouter.cs` | 重采样、音量检测、分段、写录音 | `AudioRouter.swift` |
-| `ListenEngine.cs` | 管理整条“听”的流程,处理断句和接句 | `ListenEngine.swift` |
-| `Ling.cs` | `LingClient`:同一套限流(请求间隔至少 0.6s)、优先级、`thinking: disabled`、内容放 system 消息 | `Ling.swift` |
-| `Translator.cs` | 先 Ling 后 Google;草稿只走 Google | `Translator.swift` |
-| `Notes.cs` | 纪要引擎,提示词和解析与 Mac 一致 | `Notes.swift` |
-| `SessionStore.cs` | 读写会议记录 | `SessionStore.swift` |
-| `AIKey.cs` | key 存在 `%APPDATA%\Cicada\ling-api-key`,用 DPAPI 加密,文件只给当前用户访问;不进注册表、设置、日志和导出 | `AIKey` |
-| `NotesWindow.xaml(.cs)` | 置顶、不抢焦点、默认不被截屏的纪要窗 | `NotesWindow.swift` |
-| `SubtitleBar.xaml(.cs)` | 字幕条 | `Overlay.swift` |
-| `Tray.cs` | 托盘图标和菜单 | `AppMenu.swift` |
-| `MainWindow.xaml(.cs)` | 会议记录 | `Views.swift` |
-| `DebugCommands.cs` | 本地命名管道,接收 `lsctl` 风格的调试命令 | `AppModel.debugCommand` |
-
-界面和引擎状态都在 UI 线程上处理;音频回调只把数据交给 `AudioRouter` 的队列。这条规则沿用 Mac 版。
+| `Core/Segmenter.cs` | 按音量分段:停顿 0.6s 切段,满 8s 在最后 2s 里最安静处切 | `AudioRouter.swift` 的一部分 |
+| `Core/Audio.cs` | `IAudioSource` 接口、`FileAudioSource`(测试和示例会议用)、WAV 读写 | 无 |
+| `Core/ListenEngine.cs` | 整条“听”的流程:请求并行发出、按段的顺序交付、断句接回、语言判断 | `ListenEngine.swift` |
+| `Core/Ling.cs` | `LingClient`(请求间隔至少 0.6s、优先级、`thinking: disabled`、内容放 system 消息)和 `AIKey` | `Ling.swift` |
+| `Core/Translator.cs` | Ming 三行识别(`Hear`);文字翻译先 Ling 后 Google,草稿只走 Google | `Translator.swift` |
+| `Core/Notes.cs` | 纪要引擎,提示词和解析逐字照搬 | `Notes.swift` |
+| `Core/SessionStore.cs`、`Models.cs`、`Json.cs` | 会议记录,`session.json` 格式与 Mac 一致 | `SessionStore.swift` |
+| `Core/Strings.cs` | 中文作 key,读 Mac 的 `Localizable.strings`,叠加 `Windows.strings` | `L()` |
+| `SystemAudioTap.cs` | WASAPI 进程回环,排除知了自己 | `SystemAudioTap.swift` |
+| `NotesWindow.cs` | 纪要窗和字幕条(同一个窗口的两种样子) | `NotesWindow.swift`、`Overlay.swift` |
+| `MainWindow.cs` | 会议记录 | `Views.swift` |
+| `SettingsWindow.cs`、`Onboarding.cs` | 设置、引导 | `SettingsWindow.swift`、`Onboarding.swift` |
+| `App.cs` | 入口、`Controller`(把引擎接到窗口)、托盘、调试管道 | `AppModel.swift`、`AppMenu.swift` |
+| `Native.cs` | 不抢焦点、不被截屏、DPAPI | 无 |
+
+引擎内部用锁保护状态,事件在工作线程上发出,界面统一转到 UI 线程再更新;音频回调只把数据放进 `ListenEngine` 的队列。
### 识别:Ming 分段方案的细节和代价
diff --git a/windows/src/Cicada.Core/Ling.cs b/windows/src/Cicada.Core/Ling.cs
index 96bf292..8b6ff5d 100644
--- a/windows/src/Cicada.Core/Ling.cs
+++ b/windows/src/Cicada.Core/Ling.cs
@@ -182,7 +182,9 @@ public sealed class LingClient
if (json) body["response_format"] = new JsonObject { ["type"] = "json_object" };
var payload = body.ToJsonString();
- int attempts = priority == Priority.Notes ? 4 : 1;
+ // Notes can wait; heard audio gets one retry, since on Windows a lost reply loses the words
+ // (on the Mac recognition is local and only the translation is lost); the rest fail fast.
+ int attempts = priority == Priority.Notes ? 4 : audio is not null ? 2 : 1;
double delay = 1;
for (int attempt = 1; ; attempt++)
{
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.cs
index dc2847e..a7ffa31 100644
--- a/windows/src/Cicada/App.cs
+++ b/windows/src/Cicada/App.cs
@@ -59,6 +59,13 @@ sealed class Controller
public void Launch()
{
+ // Process loopback and capture exclusion both arrived in Windows 10 2004 (build 19041).
+ if (Environment.OSVersion.Version.Build < 19041)
+ {
+ MessageBox.Show(L("知了需要 Windows 10 2004 或更新的版本。"), L("知了"));
+ application.Shutdown();
+ return;
+ }
Log.Debug($"app: launch {(Paths.Dev ? "dev" : "release")} {Environment.OSVersion.Version}");
SetUpTray();
DebugServer.Start(this);
diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.cs
index d6c2cb2..5efb744 100644
--- a/windows/src/Cicada/NotesWindow.cs
+++ b/windows/src/Cicada/NotesWindow.cs
@@ -18,6 +18,8 @@ sealed class NotesWindow : Window
ContentControl header = new(), live = new();
ScrollViewer scroll = new();
string? builtFor;
+ /// Whether Windows agreed to keep the window out of captures; if not, it's shown as visible.
+ bool hiddenFromCapture;
bool renderQueued;
public NotesWindow(Controller app)
@@ -65,8 +67,9 @@ sealed class NotesWindow : Window
public void ApplyCaptureSetting()
{
- if (!Native.SetCaptureVisible(this, app.Settings.ShowInCapture) && !app.Settings.ShowInCapture)
- Log.Debug("notes window: could not hide from capture (needs Windows 10 2004+)");
+ var ok = Native.SetCaptureVisible(this, app.Settings.ShowInCapture);
+ hiddenFromCapture = ok && !app.Settings.ShowInCapture;
+ if (!ok && !app.Settings.ShowInCapture) Log.Debug("notes window: could not hide from capture, shown as visible");
Render();
}
@@ -124,7 +127,9 @@ sealed class NotesWindow : Window
? L("正在听 · ") + Languages.Clock((DateTimeOffset.Now - session.StartedAt).TotalSeconds)
: L("知了");
var left = Ui.Row(8, Ui.Dot(listen.Listening ? Palette.Accent : Palette.Line), Ui.Text(status, 13, Palette.Ink, FontWeights.SemiBold, wrap: false));
+ // Never silently exposed: a failed exclusion gets a badge too.
if (app.Settings.ShowInCapture) left.Children.Add(WithMargin(Ui.Badge(L("对方可见")), 8));
+ else if (!hiddenFromCapture) left.Children.Add(WithMargin(Ui.Badge(L("可能被共享")), 8));
var right = Ui.Row(12,
Ui.LinkText(listen.Listening ? L("结束") : L("开始听"), () => _ = app.ToggleListening()),
Ui.LinkText(Subtitles ? L("纪要") : L("字幕"), () => app.SetView(Subtitles ? "notes" : "subtitles")),
diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.strings
index 80599f9..c377637 100644
--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings
@@ -38,3 +38,5 @@
"M月d日" = "MMM d";
"yyyy年M月d日" = "MMM d, yyyy";
"纪要停留在 %@。" = "Notes stop at %@.";
+"知了需要 Windows 10 2004 或更新的版本。" = "Cicada needs Windows 10 version 2004 or later.";
+"可能被共享" = "May be visible";
diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.strings
index b8dfcc9..f72b649 100644
--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings
@@ -38,3 +38,5 @@
"M月d日" = "M月d日";
"yyyy年M月d日" = "yyyy年M月d日";
"纪要停留在 %@。" = "メモは %@ までです。";
+"知了需要 Windows 10 2004 或更新的版本。" = "知了には Windows 10 バージョン 2004 以降が必要です。";
+"可能被共享" = "共有に映る可能性";
diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.strings
index 2abdd1e..86c3938 100644
--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings
@@ -38,3 +38,5 @@
"M月d日" = "M월 d일";
"yyyy年M月d日" = "yyyy년 M월 d일";
"纪要停留在 %@。" = "노트는 %@에서 멈춰 있습니다.";
+"知了需要 Windows 10 2004 或更新的版本。" = "Cicada에는 Windows 10 버전 2004 이상이 필요합니다.";
+"可能被共享" = "공유에 보일 수 있음";
diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.cs
index 0e81f7e..16eb38d 100644
--- a/windows/tests/Cicada.Tests/Program.cs
+++ b/windows/tests/Cicada.Tests/Program.cs
@@ -343,6 +343,19 @@ static class Tests
}
}
+ public static async Task LingRetriesAudioOnceWhenBusy()
+ {
+ int calls = 0;
+ var fake = new Fake(_ => Interlocked.Increment(ref calls) == 1 ? new HttpResponseMessage(HttpStatusCode.TooManyRequests) : Reply("LANG: en\nORIGINAL: Hi.\nTRANSLATION: 嗨。"));
+ var ling = Client(fake);
+ var reply = await ling.Chat("c", "i", Priority.Translate, model: LingClient.AudioModel, audio: [1]);
+ Check(reply.Contains("ORIGINAL: Hi."), "second attempt answered");
+ Equal(2, calls, "one retry");
+ var text = Client(new Fake(_ => new HttpResponseMessage(HttpStatusCode.TooManyRequests)));
+ try { await text.Chat("c", "i", Priority.Translate); throw new Exception("text translation retried"); }
+ catch (LingException e) { Equal(LingException.Kind.RateLimited, e.Failure, "text fails fast"); }
+ }
+
public static async Task LingMarksABadKey()
{
var ling = Client(new Fake(_ => new HttpResponseMessage(HttpStatusCode.Unauthorized)));