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): change one meeting's notes language from the live notes window, and pick my language or the meeting's own in Settings, as on the Mac

wquguru8bc6f81264f6
diff --git a/linux/cicada/app/main.py b/linux/cicada/app/main.py
index 6c15c93..2a229a6 100644
--- a/linux/cicada/app/main.py
+++ b/linux/cicada/app/main.py
@@ -74,7 +74,6 @@ class Controller:
self.store = SessionStore()
self.notes = NotesEngine(self.ling, self.store)
# 纪要语言 for notes written outside a meeting too (生成纪要 in the records window).
- self.notes.language = lambda: english_name(self.settings.notes_code)
self.translator = Translator(self.ling)
self.listen = ListenEngine(self.ling, self.translator, self.store, self.notes, self.settings)
# 同声传译: my microphone → Ming → 知了 麦克风. The listen side's loudness feeds its echo check.
@@ -124,7 +123,7 @@ class Controller:
def launch(self, speak: bool = False, background: bool = False) -> None:
ui.install_css()
lang = strings.language
- ui.DEFAULT_LANG = ui.pango_lang({"zh-Hans": "zh-CN"}.get(lang, lang)) if lang != "en" else ui.pango_lang(self.settings.notes_code)
+ ui.DEFAULT_LANG = ui.pango_lang({"zh-Hans": "zh-CN"}.get(lang, lang)) if lang != "en" else ui.pango_lang(self.settings.target_code)
backend = type(Gdk.Display.get_default()).__name__
Log.d("app: launch %s %s on %s, session %s" % ("dev" if Paths.dev else "release", sys.version.split()[0], backend,
os.environ.get("XDG_SESSION_TYPE", "?")))
diff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.py
index 147f6b2..b67ecb3 100644
--- a/linux/cicada/app/notes_window.py
+++ b/linux/cicada/app/notes_window.py
@@ -186,6 +186,11 @@ class NotesWindow(Gtk.Window):
self.tabs_wrap = ui.pad(self.tabs, 2, 16, 10, 16)
outer.pack_start(self.tabs_wrap, False, False, 0)
outer.pack_start(self.ending_wrap, False, False, 0)
+ # This meeting's languages ("English → 简体中文", the Mac's languageLink) and, opened from
+ # it, the card that changes them; after the meeting, 改用…重新整理.
+ self.lang_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
+ self.lang_wrap = ui.pad(self.lang_box, 0, 12, 8, 12)
+ outer.pack_start(self.lang_wrap, False, False, 0)
self.columns = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0, homogeneous=True)
self.scroll = Gtk.ScrolledWindow()
self.scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
@@ -211,7 +216,7 @@ class NotesWindow(Gtk.Window):
self.live_box = ui.panel(self.live, "livebox")
ui.pad(self.live_box, 6, 12, 0, 12)
outer.pack_start(self.live_box, False, False, 0)
- for w in (self.ending_wrap, self.tabs_wrap, self.scroll, self.transcript_col, self.live_box):
+ for w in (self.ending_wrap, self.tabs_wrap, self.scroll, self.transcript_col, self.live_box, self.lang_wrap):
w.set_no_show_all(True)
speak_panel = ui.panel(ui.pad(self.speakbox, 10, 16), "speakbox")
self.speakwrap = Gtk.Box()
@@ -254,6 +259,7 @@ class NotesWindow(Gtk.Window):
if self.body is not None:
self._layout()
self._fill_ending()
+ self._fill_languages()
adj = self.scroll.get_vadjustment()
keep = adj.get_value()
self._fill_body()
@@ -516,6 +522,84 @@ class NotesWindow(Gtk.Window):
# Ending by itself
+ def _names(self) -> dict:
+ from ..core.support import TARGETS
+ return {code: name for name, code in TARGETS}
+
+ def _fill_languages(self) -> None:
+ """While live: "English → 简体中文" (what they speak → the notes' language), which opens this
+ meeting's choice in place, not a popup (the window never takes focus). After the meeting: the
+ notes once more in the other language, when the meeting wasn't in mine."""
+ listen = self.app.listen
+ names = self._names()
+ name = lambda c: names.get(c, c) # noqa: E731
+ s = self._session()
+ live = listen.listening and s is not None
+ mine = self.app.settings.target_code
+ heard = listen.meeting_language(s.id) if s is not None else None
+ notes = self.app.notes
+ other = None
+ if not live and s is not None and s.lines and heard and heard != mine and notes.status != notesmod.UPDATING:
+ other = ("mine", mine) if listen.notes_choice(s.id) == "source" else ("source", heard)
+ open_ = live and getattr(self, "lang_open", False)
+ key = (live, open_, s.id if s else None, heard, listen.notes_choice(s.id) if s else None, mine, other)
+ self.lang_wrap.set_visible(live or other is not None)
+ if key == getattr(self, "_lang_key", None):
+ return
+ self._lang_key = key
+ ui.clear(self.lang_box)
+ if live:
+ # 12 px grey and underlined, as on the Mac: a quiet way in, not a button.
+ link = Gtk.Button()
+ label = ui.text((name(heard) if heard else L("自动")) + " → " + name(listen.notes_code(s.id)), 12, "secondary", wrap=False)
+ label.set_markup(label.get_label().replace("<span ", '<span underline="single" ', 1))
+ link.add(label)
+ ui.classes(link, "quietbtn")
+ link.set_relief(Gtk.ReliefStyle.NONE)
+ link.connect("clicked", lambda *_: self._toggle_languages())
+ link.set_tooltip_text(L("这场会议的语言"))
+ link.get_accessible().set_name(L("这场会议的语言"))
+ link.set_can_focus(False)
+ link.set_halign(Gtk.Align.START)
+ self.lang_box.pack_start(link, False, False, 0)
+ if open_:
+ card = ui.vbox(10)
+ top = ui.hbox(8)
+ top.pack_start(ui.text(L("这场会议的语言"), 13, "ink", bold=True, wrap=False), True, True, 0)
+ top.pack_end(ui.icon_button("window-close-symbolic", L("收起"), self._toggle_languages, focus=False), False, False, 0)
+ card.pack_start(top, False, False, 0)
+ card.pack_start(ui.vbox(6, ui.text(L("对方说"), 12, "secondary", bold=True, wrap=False),
+ ui.text(name(heard) if heard else L("还没听出来"), 13, "ink", wrap=False)), False, False, 0)
+ seg = ui.segmented([("mine", name(mine)), ("source", LF("%@(原文)", name(heard)) if heard else L("会议原文"))],
+ listen.notes_choice(s.id), lambda v: listen.set_notes_language(v, meeting_only=True))
+ for b in seg.get_children():
+ b.set_can_focus(False)
+ card.pack_start(ui.vbox(6, ui.text(L("纪要"), 12, "secondary", bold=True, wrap=False), seg,
+ ui.text(L("换了以后会马上用新语言重写纪要"), 12, "tertiary", width_chars=30)), False, False, 0)
+ settings = ui.link(L("打开语言设置"), lambda: (self._toggle_languages(), self.app.show_settings()))
+ settings.set_can_focus(False)
+ settings.set_halign(Gtk.Align.START)
+ card.pack_start(settings, False, False, 0)
+ self.lang_box.pack_start(ui.panel(ui.pad(card, 14), "notice"), False, False, 0)
+ if other is not None:
+ sid, choice = s.id, other[0]
+
+ def again():
+ listen.notes_for[sid] = choice
+ notes.generate(sid)
+ GLib.timeout_add(150, lambda: self.refresh() or False)
+ b = ui.button(LF("改用%@重新整理", name(other[1])), again, "outline")
+ b.set_can_focus(False)
+ b.set_halign(Gtk.Align.START)
+ self.lang_box.pack_start(b, False, False, 0)
+ # The box itself is no_show_all (it hides with the tabs), so show_all() on it does nothing.
+ for c in self.lang_box.get_children():
+ c.show_all()
+
+ def _toggle_languages(self) -> None:
+ self.lang_open = not getattr(self, "lang_open", False)
+ self._fill_languages()
+
def _ask_end(self) -> None:
"""结束 in the header (the Mac's askToEnd): nothing said yet just stops; otherwise the question
goes in the window, never a dialog, which would take the focus from the meeting."""
diff --git a/linux/cicada/app/settings_window.py b/linux/cicada/app/settings_window.py
index 8090512..c17bc45 100644
--- a/linux/cicada/app/settings_window.py
+++ b/linux/cicada/app/settings_window.py
@@ -199,18 +199,21 @@ class SettingsWindow(Gtk.Window):
save()
def set_notes(v):
- s.notesLanguage = v
- save()
+ app.listen.set_notes_language(v) # saves, and rewrites the live meeting's notes in it
def set_ui(v):
s.uiLanguage = v
save()
+ names = {code: name for name, code in TARGETS}
+ heard = app.listen.meeting_language(app.listen.session_id) if app.listen.listening else None
+ notes_options = [("mine", LF("我的语言 · %@", names.get(s.target_code, s.target_code))),
+ ("source", LF("会议原文 · %@", names.get(heard, heard)) if heard else L("会议原文"))]
combos = [choice(target_options(), s.target, set_target),
- choice([("system", L("和字幕一样"))] + [(c, n) for n, c in TARGETS], s.notesLanguage, set_notes),
+ ui.segmented(notes_options, s.notesLanguage, set_notes),
choice([("system", L("跟随系统")), ("zh-Hans", "简体中文"), ("en", "English"), ("ja", "日本語"), ("ko", "한국어")],
s.uiLanguage, set_ui)]
ui_row = ui.prow(L("界面语言"), combos[2], L("重启知了后生效"))
- page.pack_start(self._group(L("语言"), ui.boxed([ui.prow(L("翻译成"), combos[0]), ui.prow(L("纪要语言"), combos[1]), ui_row])),
+ page.pack_start(self._group(L("语言"), ui.boxed([ui.prow(L("翻译成"), combos[0]), ui.prow(L("纪要语言"), combos[1], L("实时纪要和完整版同一种语言")), ui_row])),
False, False, 0)
# While listening
diff --git a/linux/cicada/core/listen.py b/linux/cicada/core/listen.py
index ba68b42..2b1bbd9 100644
--- a/linux/cicada/core/listen.py
+++ b/linux/cicada/core/listen.py
@@ -61,6 +61,9 @@ class ListenEngine:
self._voice_pool = ThreadPoolExecutor(1, thread_name_prefix="Voiceprint")
self._deliver_lock = threading.Lock()
self._voices_waiting = 0
+ # 纪要语言 chosen for one meeting (the notes window's language card), over the setting.
+ self.notes_for: dict = {}
+ notes.language = lambda sid: english_name(self.notes_code(sid))
translator.glossary = notes.glossary
def on_change(self, listener) -> None:
@@ -74,6 +77,40 @@ class ListenEngine:
def target(self) -> str:
return self.settings.target_code
+ def meeting_language(self, sid: str | None) -> str | None:
+ """The language the other side spoke most in a meeting; while nothing is recorded yet, the one
+ the live meeting is being heard in (the Mac's meetingLanguage)."""
+ s = self.store.get(sid) if sid else None
+ counts: dict = {}
+ for l in (s.lines if s else []):
+ if l.speaker != "me" and l.srcLang:
+ counts[l.srcLang] = counts.get(l.srcLang, 0) + 1
+ if counts:
+ return max(counts, key=counts.get)
+ return self._hint if self.listening and sid == self.session_id else None
+
+ def notes_choice(self, sid: str | None) -> str:
+ return self.notes_for.get(sid, self.settings.notesLanguage)
+
+ def notes_code(self, sid: str | None) -> str:
+ """The language a meeting's notes are written in (the Mac's notesLanguageCode)."""
+ return self.settings.notes_code(self.notes_choice(sid), self.meeting_language(sid))
+
+ def set_notes_language(self, choice: str, meeting_only: bool = False) -> None:
+ """纪要语言 changed, in the settings or for this meeting only: a different language during a
+ meeting rewrites its notes in it right away (the Mac's setNotesLanguage)."""
+ live = self.session_id if self.listening else None
+ before = self.notes_code(live) if live else None
+ if meeting_only and live:
+ self.notes_for[live] = choice
+ else:
+ self.settings.notesLanguage = choice
+ self.settings.save()
+ if live and self.notes_code(live) != before:
+ self.notes.rewrite()
+ Log.d("notesLanguage=%s meetingOnly=%s" % (self.notes_code(live) if live else choice, meeting_only))
+ self._changed()
+
@property
def spoken(self):
with self._gate:
@@ -100,7 +137,6 @@ class ListenEngine:
self.problem_kind = None
self.heard_seconds = 0.0
self.peak = 0.0
- self.notes.language = lambda: english_name(self.settings.notes_code)
self.notes.begin(session.id)
if self.speakers is not None:
self.speakers.reset()
diff --git a/linux/cicada/core/notes.py b/linux/cicada/core/notes.py
index 64d699e..b70974e 100644
--- a/linux/cicada/core/notes.py
+++ b/linux/cicada/core/notes.py
@@ -31,12 +31,13 @@ class NotesEngine:
self._session_id = None
self._in_flight = False
self._pending_final = None
+ self._pending_fresh = None
self._last_attempt = 0.0
self._listeners = []
self.notes = MeetingNotes()
self.status = IDLE
self.shown_id = None # the session the notes belong to (stays set after the meeting ends)
- self.language = lambda: "Simplified Chinese" # the notes' language (English name), from 纪要语言
+ self.language = lambda sid: "Simplified Chinese" # a meeting's notes language (English name), from 纪要语言
self.working_id = None # the record being written now, for a "正在整理纪要…" next to it
def on_change(self, listener) -> None:
@@ -92,6 +93,13 @@ class NotesEngine:
self.notes = (s.notes if s else None) or MeetingNotes()
self._changed()
+ def rewrite(self) -> None:
+ """The live meeting's notes again from its first line (纪要语言 changed): the Mac's rewrite."""
+ with self._gate:
+ sid = self._session_id
+ if sid is not None:
+ self._work.submit(self._update, sid, False, True)
+
def generate(self, sid: str) -> None:
"""Notes for a finished meeting that has none (runs in the background)."""
self._work.submit(self._update, sid, True)
@@ -113,11 +121,13 @@ class NotesEngine:
return
self._work.submit(self._update, sid, False)
- def _update(self, sid: str, final: bool) -> None:
+ def _update(self, sid: str, final: bool, fresh: bool = False) -> None:
with self._gate:
if self._in_flight:
if final:
self._pending_final = sid
+ elif fresh:
+ self._pending_fresh = sid # after the round in the old language
return
session = self.store.get(sid)
if session is None or not session.lines:
@@ -130,12 +140,12 @@ class NotesEngine:
self.working_id = sid
self._last_attempt = time.time()
self.status = UPDATING
- base = MeetingNotes() if final else (self.notes if sid == self.shown_id else (session.notes or MeetingNotes()))
+ base = MeetingNotes() if final or fresh else (self.notes if sid == self.shown_id else (session.notes or MeetingNotes()))
self._changed()
try:
lines = self.store.lines(sid)
frm = 0 if final else min(base.covered, len(lines))
- lang = self.language()
+ lang = self.language(sid)
shown = speakers.names(session) if self.voices() else {}
p = prompt(base, lines, frm, lang, final, shown, self.voices())
nxt = None
@@ -175,11 +185,13 @@ class NotesEngine:
with self._gate:
self._in_flight = False
self.working_id = None
- queued = self._pending_final
- self._pending_final = None
+ queued, again = self._pending_final, self._pending_fresh
+ self._pending_final = self._pending_fresh = None
self._changed()
if queued is not None:
self._update(queued, final=True)
+ elif again is not None:
+ self._update(again, final=False, fresh=True)
def _min(a, b):
diff --git a/linux/cicada/core/settings.py b/linux/cicada/core/settings.py
index 1fa5a32..53944d0 100644
--- a/linux/cicada/core/settings.py
+++ b/linux/cicada/core/settings.py
@@ -12,7 +12,7 @@ DEFAULT_MODEL = "Ling-3.1-flash"
class AppSettings:
FIELDS = {
"target": "system", # what subtitles translate into; "system" follows the desktop language
- "notesLanguage": "system", # 纪要语言; "system" is the same as the subtitles'
+ "notesLanguage": "mine", # 纪要语言, the Mac's: "mine" (my language) or "source" (the meeting's own)
"model": DEFAULT_MODEL,
"view": "notes", # "notes" (the notes window, default) or "subtitles" (the subtitle bar)
"showInCapture": False, # 共享屏幕时让对方看到 (Linux can't hide it; see NotesWindow)
@@ -52,9 +52,10 @@ class AppSettings:
they speak mine (the Mac's resolvedTarget)."""
return follow_system_target(source, system_languages()) if self.target == "system" else self.target
- @property
- def notes_code(self) -> str:
- return self.target_code if self.notesLanguage == "system" else self.notesLanguage
+ def notes_code(self, choice: str | None = None, meeting: str | None = None) -> str:
+ """The notes' language for a 纪要语言 choice (this one's when None): the meeting's own language
+ (`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 speak_from_code(self) -> str:
@@ -83,6 +84,9 @@ class AppSettings:
o = jsonfmt.parse_object(f.read())
if o is not None:
kw = {k: o[k] for k, d in AppSettings.FIELDS.items() if k in o and type(o[k]) is type(d)}
+ # 纪要语言 was "system" or a language code before it took the Mac's two choices.
+ if kw.get("notesLanguage") not in (None, "mine", "source"):
+ kw["notesLanguage"] = "mine"
return AppSettings(**kw)
except OSError as e:
Log.d("settings: unreadable, defaults used (%s)" % type(e).__name__)
diff --git a/linux/tests/test_core.py b/linux/tests/test_core.py
index 19eb84c..d41558e 100644
--- a/linux/tests/test_core.py
+++ b/linux/tests/test_core.py
@@ -417,6 +417,43 @@ class Segmenting(Base):
class Notes(Base):
+ def test_notes_language_as_on_the_mac(self):
+ # "mine" or "source"; one meeting's choice over the setting; a change while live rewrites.
+ store = SessionStore()
+ settings = AppSettings(target="zh-CN", notesLanguage="source")
+ ling = client(Fake(lambda body: reply("{}")))
+ notes = NotesEngine(ling, store)
+ engine = ListenEngine(ling, Translator(ling), store, notes, settings)
+ s = store.begin()
+ for i, lang in enumerate(("en", "en", "ja")):
+ store.append(s.id, TranscriptLine(id="h%d-%d" % (i + 1, i + 1), t=i, src="x", srcLang=lang, dstLang="zh-CN"))
+ store.append(s.id, TranscriptLine(id="m1", t=4, speaker="me", src="y", srcLang="ja", dstLang="en"))
+ self.assertEqual("en", engine.meeting_language(s.id), "the other side's most spoken, not mine")
+ self.assertEqual("English", notes.language(s.id))
+ engine.notes_for[s.id] = "mine"
+ self.assertEqual("Simplified Chinese", notes.language(s.id))
+ self.assertEqual("zh-CN", AppSettings(target="zh-CN").notes_code("source", None), "nothing heard yet: mine")
+ rewrites = []
+ notes.rewrite = lambda: rewrites.append(1)
+ engine.listening, engine.session_id = True, s.id
+ engine.set_notes_language("source", meeting_only=True)
+ self.assertEqual((1, "source"), (len(rewrites), settings.notesLanguage))
+ engine.set_notes_language("source", meeting_only=True)
+ self.assertEqual(1, len(rewrites), "the same language again: nothing to rewrite")
+ engine.listening = False
+
+ def test_old_notes_language_settings_become_mine(self):
+ with open(Paths.settings(), "w", encoding="utf-8") as f:
+ f.write('{"notesLanguage" : "ja"}')
+ self.assertEqual("mine", AppSettings.load().notesLanguage)
+
+ def test_todo_owner_names_people_when_voices_are_told_apart(self):
+ lines = [TranscriptLine(id="h%d-%d" % (i, i), t=i * 3, src="we should ship this on Friday", voice=i % 2) for i in range(12)]
+ owner = lambda voices: [x for x in notesmod.prompt(MeetingNotes(), lines, 0, "English", False, voices=voices).split("\n")
+ if '"todos"' in x][0] # noqa: E731
+ self.assertIn('"owner": "对方" or "你" or null,', owner(False))
+ self.assertIn('"owner": the person\'s label from the transcript (a name like "George", or "说话人2"), "你", or null when unclear,', owner(True))
+
def test_parses_notes(self):
raw = """```json
{"title": "“发布评审”", "summary": "讨论发布。",