知了 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(linux): 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
wquguru3128d5ba4fb2
diff --git a/linux/cicada/app/debug.py b/linux/cicada/app/debug.pyindex c32368b..bb315de 100644--- a/linux/cicada/app/debug.py+++ b/linux/cicada/app/debug.py@@ -244,6 +244,11 @@ def command(app, line: str) -> dict:if cmd == "provider":app.set_ai_provider(arg)return {"ok": True, "ai": _ai(app)}+ if cmd == "switch-to-ling": # the 改用 Ling on a status line (says whether it was offered)+ offered = app.can_switch_to_ling()+ Log.d("switchToLing offered=%s" % offered)+ app.switch_to_ling()+ return {"ok": True, "offered": offered, "ai": _ai(app)}if cmd == "ai-base":# A custom service's addresses: text, voice or hear ("" for voice and hear: the text one).kind, _, url = arg.partition(" ")diff --git a/linux/cicada/app/main.py b/linux/cicada/app/main.pyindex 62ba131..802f4d0 100644--- a/linux/cicada/app/main.py+++ b/linux/cicada/app/main.py@@ -337,6 +337,15 @@ class Controller:self.settings.save()self.ai_changed()+ def can_switch_to_ling(self) -> bool:+ """改用 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. Read fresh: the key may have just been saved."""+ return self.settings.aiProvider != "ling" and AIKey(service=lambda: "ling").read() is not None++ def switch_to_ling(self) -> None:+ if self.can_switch_to_ling():+ self.set_ai_provider("ling")+def set_ai_model(self, kind: str, model: str) -> None:"""A model chosen over the recommended one ("text", "hear" or "voice"; "" goes back to it)."""s = self.settingsdiff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.pyindex 5b79820..ef267a6 100644--- a/linux/cicada/app/notes_window.py+++ b/linux/cicada/app/notes_window.py@@ -881,21 +881,24 @@ class NotesWindow(Gtk.Window):ui.retext(self.footer_time, L("刚刚更新") if ago < 10 else LF("%lld 秒前更新", ago) if ago < 60 else LF("%lld 分钟前更新", ago // 60))def _banner(self, body, engine) -> None:- """Why the notes stopped, above them, notes or not (the Mac's banner): a dead key, too many- requests, or a round that failed; each says where the notes stop."""+ """Why the notes stopped, above them, notes or not (the Mac's banner): one status line for a+ dead key, a busy or unreachable service, or a round that failed; each says what waits and+ what still works."""s = self._session()covered = engine.notes.coveredlast = s.lines[covered - 1].t if s is not None and 0 < covered <= len(s.lines) else 0.0reason = self._reason()ling = self.app.ling- # Who the banners name: a custom service by its address, which says more than 这个服务.+ # Who the line names: a custom service by its address, which says more than 这个服务.name = ling.service_host if ling.provider.id == "custom" and ling.service_host else ling.service_name# All but the key are about a round of the meeting going on now: a record opened later has none.live = self.app.listen.listening- if engine.status == notesmod.INVALID_KEY:- text = (LF("key 已失效(被删或额度用完),纪要暂停在 %@。", clock(last)) if last > 0- else L("key 已失效(被删或额度用完),换个 key 就能开始写纪要。"))- tone = "error"+ status = engine.status+ action = on_action = None+ if status == notesmod.INVALID_KEY:+ tone = "needsyou"+ text = LF("key 失效了 · 纪要停在 %@", clock(last)) if last > 0 else L("key 失效了 · 纪要等新的 key")+ action, on_action = L("换 key"), lambda: self.app.show_settings(ai=True)elif problem.blocking(reason) and (reason in problem.NOTES_ONLY or not self.live_box.get_visible()):# Only the user can fix it (the live card says it too, when it shows): what, and 打开设置.from .aicheck_view import blocking, blocking_detail@@ -908,30 +911,24 @@ class NotesWindow(Gtk.Window):row.pack_end(b, False, False, 0)body.pack_start(ui.pad(ui.panel(ui.pad(row, 12), "notice", "error"), 0, 0, 10, 0), False, False, 0)return- elif engine.status == notesmod.RATE_LIMITED and live:- text, tone = LF("%@ 很忙,纪要稍后补上。字幕照常。", name), "busy"- elif engine.status == notesmod.UNREACHABLE and live and ling.check_result.reason == "unreachable":- # 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 answers nothing; notes that only timed out- # while translations still came back retry on the next round.- text = (LF("连不上 %@,纪要暂停在 %@,连上后自动继续。", name, clock(last)) if last > 0- else LF("连不上 %@,连上后开始写纪要。", name))- tone = "error"- elif engine.status == notesmod.FAILED and live:- text, tone = L("这轮没整理好,下一轮会自动重试。"), ""+ elif status == notesmod.RATE_LIMITED and live:+ # A 429 holds hearing at the start gate and its retries wait it out: subtitles come late+ # for a moment, not lost; the live card says so if hearing itself stays busy.+ tone, text = "waiting", LF("%@ 很忙 · 纪要稍后补上,字幕照常", name)+ elif status in (notesmod.UNREACHABLE, notesmod.UPDATING) and live and ling.check_result.reason == "unreachable":+ # The network or the proxy, not the notes: it picks up by itself. Both: the notes' own+ # request failed and the service answers nothing (notes that only timed out while+ # translations came back retry next round). The retry that follows (UPDATING) hangs as+ # long as a timeout: the line stays meanwhile. The service hears the meeting here, so the+ # subtitles wait too.+ tone, text = "waiting", LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", name)+ if self.app.can_switch_to_ling():+ action, on_action = L("改用 Ling"), self.app.switch_to_ling+ elif status == notesmod.FAILED and live:+ tone, text = "info", L("这轮纪要没写好 · 下轮自动补上")else:return- row = ui.hbox(10)- row.pack_start(ui.text(text, 12, "ink", width_chars=24), True, True, 0)- if tone == "error":- unreachable = engine.status == notesmod.UNREACHABLE- b = ui.button(L("设置") if unreachable else L("更换 key"), lambda: self.app.show_settings(ai=True),- "outline" if unreachable else "darkbtn")- b.set_can_focus(False)- b.set_valign(Gtk.Align.CENTER)- row.pack_end(b, False, False, 0)- card = ui.panel(ui.pad(row, 12), "notice", *([tone] if tone else []))- body.pack_start(ui.pad(card, 0, 0, 10, 0), False, False, 0)+ body.pack_start(ui.pad(ui.status_line(tone, text, action, on_action), 0, 0, 10, 0), False, False, 0)def _listening_view(self) -> Gtk.Widget:"""NotesListeningView: one quiet status row, then the notes' own shape waiting to be filled, sodiff --git a/linux/cicada/app/ui.py b/linux/cicada/app/ui.pyindex 74e84f1..fff262f 100644--- a/linux/cicada/app/ui.py+++ b/linux/cicada/app/ui.py@@ -108,6 +108,12 @@ spinner { color: #6B7080; }.notice { background-color: #F2F3F5; border-radius: 12px; }dialog.endask { background-color: #FFFFFF; border: 1px solid #E4E6EA; border-radius: 12px; }.notice.error { background-color: #FDECEA; }+/* StatusLine (Views.swift): a service in trouble in one line on the plain fill; colour only in the dot. */+.statusline { background-color: #F2F3F5; border-radius: 10px; min-height: 36px; }+.statusdot { border-radius: 3px; min-width: 6px; min-height: 6px; background-color: #6B7080; }+.statusdot.waiting { background-color: #C98A00; }+.statusdot.needsyou { background-color: #B42318; }+button.quietbtn.statusaction, button.quietbtn.statusaction:hover { background-color: transparent; padding: 4px 0; min-width: 0; }.panel.dark .endingstrip { background-color: rgba(232,85,43,0.16); }entry.notes-search { min-height: 32px; font-size: 13px; border-radius: 9px; }.panel.dark entry.notes-search { background-color: #2A2C32; color: #F2F3F5; }@@ -147,7 +153,6 @@ button.iconbtn.on { background-color: #F3F4F6; color: #15171C; }.proxybox label { color: #3D4149; }.warnstrip { background-color: #FFF4D6; border-radius: 10px; }.warnstrip label { color: #8A5A00; }-.notice.busy { background-color: #FFF4D6; }.busyline { color: #8A5A00; }.chip { background-color: #F2F3F5; border-radius: 5px; padding: 1px 6px; color: #15171C; }.chip.now { background-color: #E8552B; color: #FFFFFF; }@@ -531,6 +536,33 @@ def link(label: str, on_click) -> Gtk.Button:return b+def status_line(tone: str, s: str, action: str | None = None, on_action=None) -> Gtk.EventBox:+ """A service in trouble, said the same way wherever it shows (the Mac's 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: "waiting" (yellow) comes back by itself, "needsyou" (red)+ needs the user, "info" (grey) is just so they know."""+ row = hbox(8)+ d = Gtk.Box()+ d.set_size_request(6, 6)+ d.set_valign(Gtk.Align.CENTER)+ d.set_halign(Gtk.Align.CENTER)+ classes(d, "statusdot", tone)+ row.pack_start(d, False, False, 0)+ label = text(s, 12, "secondary", width_chars=24)+ label.set_valign(Gtk.Align.CENTER)+ row.pack_start(label, True, True, 0)+ if action:+ b = Gtk.Button()+ b.add(text(action, 12, "ink", bold=True, wrap=False, ellipsize=False))+ classes(b, "quietbtn", "statusaction")+ b.set_relief(Gtk.ReliefStyle.NONE)+ b.set_can_focus(False) # the notes window never takes focus+ b.set_valign(Gtk.Align.CENTER)+ b.connect("clicked", lambda *_: on_action())+ row.pack_end(b, False, False, 0)+ return panel(pad(row, 7, 12), "statusline")++def dot(live: bool) -> Gtk.Widget:d = Gtk.Box()d.set_size_request(9, 9)diff --git a/linux/cicada/core/listen.py b/linux/cicada/core/listen.pyindex 9b11865..7281f5c 100644--- a/linux/cicada/core/listen.py+++ b/linux/cicada/core/listen.py@@ -593,12 +593,14 @@ def problem(e: LingError, service: str, hear_model: str = ""):return "busy", LF("%@ 暂时出错(HTTP %lld),稍后再试。", service, e.status)kind = {LingError.NO_KEY: "key", LingError.INVALID_KEY: "key", LingError.RATE_LIMITED: "busy",LingError.NETWORK: "network", LingError.TIMEOUT: "network"}.get(e.kind)+ # Out of reach: the service hears the meeting here, so subtitles wait along with the notes.+ away = LF("字幕和纪要等 %@ 恢复 · 连上后自动继续", service)if ling:text = {LingError.NO_KEY: L("需要 Ling key 才能听"), LingError.INVALID_KEY: L("Ling key 无效"),- LingError.RATE_LIMITED: L("Ling 太忙,稍后再试"), LingError.NETWORK: L("连不上 Ling"),- LingError.TIMEOUT: L("连不上 Ling")}.get(e.kind)+ LingError.RATE_LIMITED: L("Ling 太忙,稍后再试"), LingError.NETWORK: away,+ LingError.TIMEOUT: away}.get(e.kind)else:text = {LingError.NO_KEY: LF("需要 %@ 的 key 才能听", service), LingError.INVALID_KEY: LF("%@ 的 key 无效", service),- LingError.RATE_LIMITED: LF("%@ 太忙,稍后再试", service), LingError.NETWORK: LF("连不上 %@", service),- LingError.TIMEOUT: LF("连不上 %@", service)}.get(e.kind)+ LingError.RATE_LIMITED: LF("%@ 太忙,稍后再试", service), LingError.NETWORK: away,+ LingError.TIMEOUT: away}.get(e.kind)return kind, textdiff --git a/linux/cicada/core/speak.py b/linux/cicada/core/speak.pyindex 2fe476f..cd0fc61 100644--- a/linux/cicada/core/speak.py+++ b/linux/cicada/core/speak.py@@ -198,7 +198,7 @@ class SpeakEngine:heard = Noneif heard is None:# Never the original, never a guess.- self.problem = strings.L("翻译失败,这句话未发送")+ self.problem = strings.L("这句没翻译成 · 没有说出去")Log.d("speak: segment %d %.1fs not interpreted, not spoken" % (seg.index, seg.seconds))return Noneoriginal, translation = hearddiff --git a/linux/tests/test_providers.py b/linux/tests/test_providers.pyindex a0fa714..62f7849 100644--- a/linux/tests/test_providers.py+++ b/linux/tests/test_providers.py@@ -261,7 +261,7 @@ class Words(Base):def test_problems_name_the_service(self):self.assertEqual("key", problem(LingError(LingError.HTTP, 400), "ZenMux")[0])self.assertIn("ZenMux", problem(LingError(LingError.NETWORK), "ZenMux")[1])- self.assertEqual(("network", "连不上 Ling"), problem(LingError(LingError.TIMEOUT), "Ling"))+ self.assertEqual(("network", "字幕和纪要等 Ling 恢复 · 连上后自动继续"), problem(LingError(LingError.TIMEOUT), "Ling"))self.assertIsNone(problem(LingError(LingError.HTTP, 400), "Ling")[0])# A gateway's 502 in front of the server: the service's trouble, not the network or the key.self.assertEqual(("busy", "ZenMux 暂时出错(HTTP 502),稍后再试。"), problem(LingError(LingError.HTTP, 502), "ZenMux"))