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.

feat(linux): with your own AI service, meeting audio and text can stay off Google Translate

wquguru31aee74c6213
diff --git a/linux/cicada/app/debug.py b/linux/cicada/app/debug.py
index aee13cc..e7d37bf 100644
--- a/linux/cicada/app/debug.py
+++ b/linux/cicada/app/debug.py
@@ -6,6 +6,7 @@ per connection, one JSON line back. Never in release builds.
target <code> | key-reload | windows | select <record id> | append <record id> <n> (a growing meeting)
provider ling|openrouter|zenmux|custom | ai-model hear|text|voice <id> (设置 › AI 服务; "" back to the recommended) |
ai-base text|voice|hear <url> (其他(兼容 OpenAI)'s addresses; "" for voice/hear: the text one)
+ ai-custom-only on|off (语音和文字只发给你的服务, the Mac's aiCustomOnly)
speak-enable on|off | speak on|off (同声传译) | quit
calls <program=name,…>|none|real (meeting apps in a call) | endtimes <silence> <countdown> <grace>|off | endkeep
notes-tab notes|transcript | notes-search <text> | notes-wide on|off | onboarding-step <n> | settings-scroll <0-1>
@@ -266,6 +267,9 @@ def command(app, line: str) -> dict:
app.settings.save()
app.ai_changed()
return {"ok": True, "ai": _ai(app)}
+ if cmd == "ai-custom-only":
+ app.set_custom_only(arg == "on")
+ return {"ok": True, "ai": _ai(app)}
if cmd == "ai-model":
kind, _, model = arg.partition(" ")
app.set_ai_model(kind, model.strip())
@@ -421,4 +425,6 @@ def _ai(app) -> dict:
"proxyLine": ling.check_result.proxy_line(ling.service_name, ling.service_host),
"keyWorks": app.key_works, "asking": getattr(app, "_asking", None) is not None,
"lastVoice": list(ling.last_voice) if ling.last_voice else None, "simulate": ling.simulate,
- "catalog": [len(ling.text_catalog), len(ling.hear_catalog)], "keyFile": os.path.basename(app.key.path)}
+ "catalog": [len(ling.text_catalog), len(ling.hear_catalog)], "keyFile": os.path.basename(app.key.path),
+ "customOnly": app.settings.aiCustomOnly, "googleOff": app.translator.google_off,
+ "sentencesUntranslated": app.translator.sentences_untranslated}
diff --git a/linux/cicada/app/main.py b/linux/cicada/app/main.py
index eb2aa09..5ab57ff 100644
--- a/linux/cicada/app/main.py
+++ b/linux/cicada/app/main.py
@@ -76,6 +76,7 @@ class Controller:
self.notes = NotesEngine(self.ling, self.store)
# 纪要语言 for notes written outside a meeting too (生成纪要 in the records window).
self.translator = Translator(self.ling)
+ self.translator.google_off = self.settings.google_off
self.listen = ListenEngine(self.ling, self.translator, self.store, self.notes, self.settings)
# 同声传译: my microphone → the AI service → 知了 麦克风. The listen side's loudness feeds its echo check.
from ..core.speak import SpeakEngine
@@ -395,10 +396,21 @@ class Controller:
def ai_changed(self) -> None:
"""The service, its address, models or key changed: forget the old check and check again."""
+ self.translator.google_off = self.settings.google_off
self.ling.key_changed()
if self.ling.has_key:
threading.Thread(target=self.ling.check, daemon=True).start()
+ def set_custom_only(self, on: bool) -> None:
+ """语音和文字只发给你的服务: Google is never asked while the custom service is in use. Nothing
+ to check again: only where translations go changes."""
+ self.settings.aiCustomOnly = on
+ self.settings.save()
+ self.translator.google_off = self.settings.google_off
+ if self.settings_window is not None:
+ self.settings_window.show_key_state() # the switch, its grey line and the footnote
+ self.changed()
+
def recheck(self) -> None:
"""重新检查: the AI service, step by step, off the main loop."""
if self.ling.has_key and not self.ling.check_result.running:
diff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.py
index 6254a2c..351f634 100644
--- a/linux/cicada/app/notes_window.py
+++ b/linux/cicada/app/notes_window.py
@@ -864,6 +864,12 @@ 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 live and self.app.translator.google_off and self.app.translator.sentences_untranslated:
+ # 语音和文字只发给你的服务, and the service didn't translate the last sentence: it picks up
+ # by itself, and no 改用 Ling, which would send the meeting elsewhere.
+ notes_wait = status in (notesmod.UNREACHABLE, notesmod.UPDATING) and ling.check_result.reason == "unreachable"
+ tone = "waiting"
+ text = LF("译文和纪要等 %@ 恢复 · 字幕先显示原文", name) if notes_wait else LF("译文等 %@ 恢复 · 字幕先显示原文", name)
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.
diff --git a/linux/cicada/app/settings_window.py b/linux/cicada/app/settings_window.py
index 815f3a0..7827e4f 100644
--- a/linux/cicada/app/settings_window.py
+++ b/linux/cicada/app/settings_window.py
@@ -660,7 +660,14 @@ class SettingsWindow(Gtk.Window):
("hear", L("听对方"), hear_body)):
rows.append(ui.vbox(0, self._custom_head(sid, title), self._custom_body(sid, body)))
hint = ui.text(L("每样可以接不同的机器;这台电脑和局域网里的服务可以用 http。"), 12, "tertiary", width_chars=60)
- page = ui.vbox(6, ui.pad(hint, 0, 2, 0, 2), ui.boxed(rows))
+ # 语音和文字只发给你的服务 (AISettings.swift › onlyRow): Google is never asked. The grey line says
+ # what it costs, and while the service can't be reached, that new lines are the original only.
+ self.only_switch = Gtk.Switch()
+ self.only_switch.set_active(s.aiCustomOnly)
+ self.only_switch.connect("notify::active", self._only_toggled)
+ self.only_detail = ui.text(L("不用 Google 翻译;说话时要等整句说完才出译文"), 11, "tertiary", width_chars=50)
+ only = ui.boxed([ui.prow(L("语音和文字只发给你的服务"), self.only_switch, subtitle_widget=self.only_detail)])
+ page = ui.vbox(6, ui.pad(hint, 0, 2, 0, 2), ui.boxed(rows), only)
page.set_no_show_all(True)
for w in page.get_children():
w.show_all()
@@ -670,6 +677,10 @@ class SettingsWindow(Gtk.Window):
body.set_visible(False)
return page
+ def _only_toggled(self, w, _p) -> None:
+ if w.get_active() != self.app.settings.aiCustomOnly:
+ self.app.set_custom_only(w.get_active())
+
@staticmethod
def _label(title: str) -> Gtk.Widget:
l = ui.text(title, 12, "secondary", wrap=False, ellipsize=False)
@@ -804,7 +815,7 @@ class SettingsWindow(Gtk.Window):
head("text", state, "%s · %s" % (host, c.text_model) if host and c.text_model else L("填上地址和模型"), trailing,
"warn" if r.slow else "stepwhy" if text_failed and have else "")
ui.clear(self.custom_text_status)
- slow = r.slow_line()
+ slow = r.slow_line(google_off=s.aiCustomOnly) # this page is the custom service's
if slow:
self.custom_text_status.pack_start(ui.text(slow, 12, "warn", width_chars=46), False, False, 0)
if have and aicheck_view.show_steps(r) and (text_failed or r.running or r.busy):
@@ -853,6 +864,13 @@ class SettingsWindow(Gtk.Window):
self.custom_hear_status.pack_start(ui.text(L("地址要用 https;这台电脑和局域网里的服务可以用 http。"), 12, "stepwhy",
width_chars=46), False, False, 0)
self.custom_hear_status.show_all()
+ # 语音和文字只发给你的服务: set by a debug command too. Linux has no translation of its own to
+ # stand in while the service can't be reached.
+ on = s.aiCustomOnly
+ if self.only_switch.get_active() != on:
+ self.only_switch.set_active(on) # _only_toggled sees it already saved
+ down = on and have and not r.running and f is not None and f[1] != aicheck.BUSY
+ ui.retext(self.only_detail, L("现在连不上:新字幕暂时只有原文") if down else L("不用 Google 翻译;说话时要等整句说完才出译文"))
# A service that isn't set up yet, or doesn't work, opens where it needs filling in.
if not getattr(self, "_custom_opened", False):
self._custom_opened = True
@@ -1058,7 +1076,11 @@ class SettingsWindow(Gtk.Window):
# for the hear model's address (never 声音不出本机 on a port).
from ..core.providers import is_nearby
cost = L("跑在你自己的机器上,不按量计费。") if c.base and is_nearby(c.base) else L("费用以这个服务为准。")
- ui.retext(self.footnote, cost + LF("听的时候,电脑里的声音会发给 %@。", app.ling.hear_host or L("你填的地址")))
+ if app.settings.aiCustomOnly:
+ from ..core.providers import only_host
+ ui.retext(self.footnote, cost + LF("会议的语音和文字只发给 %@,不经过 Google 等外部服务。", only_host(c) or L("你填的地址")))
+ else:
+ ui.retext(self.footnote, cost + LF("听的时候,电脑里的声音会发给 %@。", app.ling.hear_host or L("你填的地址")))
else:
ui.retext(self.footnote, LF("听的时候,电脑里的声音会发给 %@。", name) if p.id == "ling"
else L("按所选模型计费。") + LF("听的时候,电脑里的声音会发给 %@。", name))
diff --git a/linux/cicada/app/ui.py b/linux/cicada/app/ui.py
index 0c09858..9ed195e 100644
--- a/linux/cicada/app/ui.py
+++ b/linux/cicada/app/ui.py
@@ -665,13 +665,17 @@ def boxed(rows) -> Gtk.Widget:
return panel(box, "boxed")
-def prow(title: str, control: Gtk.Widget | None = None, subtitle: str | None = None, title_widget=None) -> Gtk.Widget:
- """One preferences row: title (and a grey subtitle) on the left, its control on the right."""
+def prow(title: str, control: Gtk.Widget | None = None, subtitle: str | None = None, title_widget=None,
+ subtitle_widget=None) -> Gtk.Widget:
+ """One preferences row: title (and a grey subtitle) on the left, its control on the right.
+ `subtitle_widget`: a grey line the caller rewrites later, in place of `subtitle`."""
row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
left.set_valign(Gtk.Align.CENTER)
left.pack_start(title_widget or text(title, 13, "ink", wrap=False, ellipsize=False), False, False, 0)
- if subtitle:
+ if subtitle_widget is not None:
+ left.pack_start(subtitle_widget, False, False, 0)
+ elif subtitle:
left.pack_start(text(subtitle, 11, "tertiary", width_chars=50), False, False, 0)
row.pack_start(left, True, True, 0)
if control is not None:
diff --git a/linux/cicada/core/aicheck.py b/linux/cicada/core/aicheck.py
index d9b7ff1..6c10b8a 100644
--- a/linux/cicada/core/aicheck.py
+++ b/linux/cicada/core/aicheck.py
@@ -180,12 +180,17 @@ class AICheck:
SERVER_ERROR: lambda: LF("%@ 暂时出错(HTTP %lld),稍后再试。", service, code or 0),
}[reason]()
- def slow_line(self) -> str | None:
+ def slow_line(self, google_off: bool = False) -> str | None:
"""Why translations are slow, and what to do (a custom service). Linux falls back to Google
- too (Translator.translate, 6 s), so the Mac's words hold."""
+ too (Translator.translate, 6 s), so the Mac's words hold; with 语音和文字只发给你的服务
+ (`google_off`) a sentence over 6 s is given up on instead (AICheck.slowLine(googleOff:))."""
if not self.slow:
return None
secs = "%.1f" % self.translate.seconds
+ if google_off:
+ if self.translate.thinks:
+ return LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒这句就不等它了。在服务端关掉思考,或换一个不思考的模型。", secs)
+ return LF("翻一句要 %@ 秒,超过 6 秒这句就不等它了。换一个更小的模型会快一些。", secs)
if self.translate.thinks:
return LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒会改用 Google。在服务端关掉思考,或换一个不思考的模型。", secs)
return LF("翻一句要 %@ 秒,超过 6 秒会改用 Google。换一个更小的模型会快一些。", secs)
diff --git a/linux/cicada/core/listen.py b/linux/cicada/core/listen.py
index 0ac1713..c374bc2 100644
--- a/linux/cicada/core/listen.py
+++ b/linux/cicada/core/listen.py
@@ -579,8 +579,12 @@ class ListenEngine:
def retranslate():
dst = self.translator.translate(src, line.srcLang, target, Translator.SENTENCE)
+ if dst is None:
+ # The notes window may now say the user's own service can't be reached.
+ self._changed()
+ return
with self._gate:
- if dst is None or line.src != src:
+ if line.src != src:
return
line.dst = dst
updated = line.copy()
diff --git a/linux/cicada/core/providers.py b/linux/cicada/core/providers.py
index e675afa..9501d7e 100644
--- a/linux/cicada/core/providers.py
+++ b/linux/cicada/core/providers.py
@@ -275,3 +275,12 @@ def catalog(data: str | dict, recommended: list, hears: bool) -> list:
ids.append(mid)
rest = sorted(i for i in ids if i not in recommended)
return list(recommended) + rest
+
+
+def only_host(c: AIConfig) -> str | None:
+ """Where a custom service's audio and text go, when every use shares one host (text, hear, and
+ the voice if set up); None when they differ (AISettings.swift › customHosts)."""
+ urls = [c.base, c.hear_url] + ([c.voice_base] if c.has_voices else [])
+ hosts = {urllib.parse.urlsplit(u).hostname for u in urls if u}
+ hosts.discard(None)
+ return hosts.pop() if len(hosts) == 1 else None
diff --git a/linux/cicada/core/settings.py b/linux/cicada/core/settings.py
index 3eaeefa..fb6e993 100644
--- a/linux/cicada/core/settings.py
+++ b/linux/cicada/core/settings.py
@@ -26,6 +26,9 @@ class AppSettings:
# The custom service's hear model at an address of its own (the port's, like the Mac's
# aiCustomHearBase); empty: the same address as the text model.
"aiCustomHearBase": "",
+ # 语音和文字只发给你的服务 (the Mac's aiCustomOnly): with the custom service, Google Translate is
+ # never asked. Kept when another service is picked, but only acts on the custom one.
+ "aiCustomOnly": False,
"view": "notes", # "notes" (the notes window, default) or "subtitles" (the subtitle bar)
"showInCapture": False, # 共享屏幕时让对方看到 (Linux can't hide it; see NotesWindow)
"onboarded": False,
@@ -83,6 +86,11 @@ class AppSettings:
(`meeting`, the one it was heard in) for "source", else mine (the Mac's notesLanguageCode)."""
return meeting if (choice or self.notesLanguage) == "source" and meeting else self.target_code
+ @property
+ def google_off(self) -> bool:
+ """语音和文字只发给你的服务 in effect: on, and the custom service in use."""
+ return self.aiProvider == "custom" and self.aiCustomOnly
+
@property
def hears_room(self) -> bool:
"""The room microphone is open: 会议室 or 电脑和会议室."""
diff --git a/linux/cicada/core/translator.py b/linux/cicada/core/translator.py
index 3c4e655..402d96a 100644
--- a/linux/cicada/core/translator.py
+++ b/linux/cicada/core/translator.py
@@ -28,6 +28,10 @@ class Translator:
self.transport = transport
self._google_backoff_until = 0.0
self._last_unreachable_try = 0.0
+ self._google_off = False
+ # The last finished sentence came back untranslated (TranslationHealth.sentencesUntranslated):
+ # with Google left out, the notes window says the translation waits for the user's service.
+ self.sentences_untranslated = False
# Names and terms the notes have settled on, e.g. "江充 (…; misheard as 江松)".
self.glossary = lambda: []
@@ -67,10 +71,33 @@ class Translator:
self._last_unreachable_try = now
return True
+ @property
+ def google_off(self) -> bool:
+ """语音和文字只发给你的服务 (custom service only, set by the app): Google is never asked, so the
+ text stays with the user's service. A stale backoff goes with it either way."""
+ return self._google_off
+
+ @google_off.setter
+ def google_off(self, on: bool) -> None:
+ if on == self._google_off:
+ return
+ self._google_off = on
+ self._google_backoff_until = 0.0
+ self.sentences_untranslated = False
+
def translate(self, text: str, source: str, target: str, kind: str) -> str | None:
"""Ling (finished sentences only) → Google. None when both fail."""
if source == target:
return text
+ # Partial text only ever goes to Google: left out, it shows the original until the sentence ends.
+ if kind == self.DRAFT and self._google_off:
+ return None
+ out = self._translate(text, source, target, kind)
+ if kind != self.DRAFT:
+ self.sentences_untranslated = out is None
+ return out
+
+ def _translate(self, text: str, source: str, target: str, kind: str) -> str | None:
if kind != self.DRAFT and self.ling.usable and self._ling_worth_trying():
try:
frm = "the spoken language" if source == "auto" else english_name(source)
@@ -86,6 +113,8 @@ class Translator:
return cleaned
except LingError as e:
Log.d("translate ling failed: %s" % e)
+ if self._google_off:
+ return None # left out on purpose: the original only, and no word about Google failing
if time.time() < self._google_backoff_until:
return None
try:
diff --git a/linux/tests/test_custom.py b/linux/tests/test_custom.py
index 6ca551a..17b8d20 100644
--- a/linux/tests/test_custom.py
+++ b/linux/tests/test_custom.py
@@ -100,8 +100,15 @@ class Shape(unittest.TestCase):
self.assertTrue(r.slow)
self.assertIn("4.2", r.slow_line())
self.assertIn("思考", r.slow_line())
+ self.assertIn("Google", r.slow_line())
+ # 语音和文字只发给你的服务: no Google to fall back on, the sentence is given up on.
+ self.assertNotIn("Google", r.slow_line(google_off=True))
+ self.assertIn("不等它了", r.slow_line(google_off=True))
+ self.assertIn("思考", r.slow_line(google_off=True))
r.translate = aicheck.Speed(3.5, False)
self.assertNotIn("思考", r.slow_line())
+ self.assertIn("不等它了", r.slow_line(google_off=True))
+ self.assertNotIn("思考", r.slow_line(google_off=True))
r.translate = aicheck.Speed(0.5, False)
self.assertIsNone(r.slow_line())
self.assertIn("translate=0.5s", r.summary())
@@ -251,5 +258,95 @@ class HearAddress(Base):
self.assertFalse(any("input_audio" in b for _u, b in fake.sent))
+class StubLing:
+ """The service, for the translator alone: answers each sentence, or fails."""
+
+ def __init__(self, answer=None):
+ self.usable = True
+ self.answer = answer # None: the service can't be reached
+ self.asked = []
+ self.check_result = aicheck.AICheck() # not checked yet: every sentence is tried
+
+ def chat(self, prompt, user, priority, **kw):
+ self.asked.append(prompt)
+ if self.answer is None:
+ raise LingError("unreachable")
+ return self.answer
+
+
+GOOGLE = Response(200, '[[["周五发布。","We ship on Friday",null,null,1]]]')
+
+
+class GoogleOff(unittest.TestCase):
+ """语音和文字只发给你的服务 (issue #15, TranslatorTests.swift › GoogleOffTests): Google is never asked."""
+
+ def translator(self, ling, google=GOOGLE):
+ from cicada.core.translator import Translator
+ fake = Fake(lambda u, b: google)
+ return Translator(ling, transport=fake), fake
+
+ def test_partial_lines_show_the_original_without_asking_anyone(self):
+ from cicada.core.translator import Translator
+ ling = StubLing("周五发布。")
+ t, fake = self.translator(ling)
+ t.google_off = True
+ for _ in range(3):
+ self.assertIsNone(t.translate("We ship on Friday", "en", "zh-CN", Translator.DRAFT))
+ self.assertEqual([], fake.sent)
+ self.assertEqual([], ling.asked) # partial text never goes to the AI service either
+ self.assertFalse(t.sentences_untranslated)
+
+ def test_finished_sentences_go_to_the_service_only(self):
+ from cicada.core.translator import Translator
+ ling = StubLing("周五发布。")
+ t, fake = self.translator(ling)
+ t.google_off = True
+ self.assertEqual("周五发布。", t.translate("We ship on Friday", "en", "zh-CN", Translator.SENTENCE))
+ self.assertFalse(t.sentences_untranslated)
+ ling.answer = None
+ self.assertIsNone(t.translate("We ship on Friday", "en", "zh-CN", Translator.SENTENCE))
+ self.assertTrue(t.sentences_untranslated)
+ self.assertEqual([], fake.sent)
+
+ def test_off_google_still_stands_in(self):
+ from cicada.core.translator import Translator
+ t, fake = self.translator(StubLing(None))
+ self.assertEqual("周五发布。", t.translate("We ship on Friday", "en", "zh-CN", Translator.SENTENCE))
+ self.assertEqual("周五发布。", t.translate("We ship on Friday", "en", "zh-CN", Translator.DRAFT))
+ self.assertEqual(2, len(fake.sent))
+
+ def test_flipping_it_clears_a_stale_google_backoff(self):
+ from cicada.core.translator import Translator
+ t, fake = self.translator(StubLing(None), google=Response(429, ""))
+ self.assertIsNone(t.translate("Hello", "en", "zh-CN", Translator.DRAFT))
+ self.assertGreater(t._google_backoff_until, 0)
+ t.google_off = True
+ self.assertEqual(0.0, t._google_backoff_until)
+ t.translate("Hello", "en", "zh-CN", Translator.SENTENCE)
+ self.assertTrue(t.sentences_untranslated)
+ t.google_off = False
+ self.assertFalse(t.sentences_untranslated)
+ fake.respond = lambda u, b: GOOGLE
+ self.assertEqual("周五发布。", t.translate("Hello", "en", "zh-CN", Translator.DRAFT))
+
+ def test_only_with_the_custom_service(self):
+ s = AppSettings(aiProvider="custom", aiCustomOnly=True, **custom())
+ self.assertTrue(s.google_off)
+ s.aiProvider = "ling"
+ self.assertFalse(s.google_off) # kept, but inert
+ self.assertTrue(s.aiCustomOnly)
+ self.assertFalse(AppSettings(aiProvider="custom", **custom()).google_off)
+
+ def test_the_footnote_names_one_host_only_when_every_use_shares_it(self):
+ s = AppSettings(aiProvider="custom", **custom())
+ self.assertEqual("192.168.1.20", providers.only_host(s.ai_config()))
+ s.aiCustomHearBase = "http://192.168.1.30:8000/v1"
+ self.assertIsNone(providers.only_host(s.ai_config()))
+ s.aiCustomHearBase = ""
+ s.aiVoiceModels = {"custom": "qwen3-tts"}
+ s.aiCustomVoiceBase = "http://192.168.1.40:8000/v1"
+ self.assertIsNone(providers.only_host(s.ai_config()))
+
+
if __name__ == "__main__":
unittest.main()