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.

fix(linux): searching the records with Ctrl+F opens the meeting at the line found and highlights it

wquguru58a0c5fa1e81
diff --git a/linux/cicada/app/debug.py b/linux/cicada/app/debug.py
index 9a4c05b..d4df08d 100644
--- a/linux/cicada/app/debug.py
+++ b/linux/cicada/app/debug.py
@@ -11,6 +11,8 @@ per connection, one JSON line back. Never in release builds.
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>
+ records-search <text> (typed into the records window's Ctrl+F search) | records-search-step 1|-1 (Enter / the arrows):
+ how many meetings it finds, the shown one, its matches and the line being looked at
settings-models on|off (unfold 自己选模型)
ai-check-sim <reason|lowBalance|off> (every check ends this way: screenshots of each state) | ai-check (check now)
ask settings|fix|close (answer the 开始听 dialog a failed check put up) | settings-ai (设置 at AI 服务) | tray-menu
@@ -461,6 +463,21 @@ def command(app, line: str) -> dict:
else:
w.set_wide(arg == "on")
return {"ok": True, "tab": w.tab, "wide": w.wide, "matches": len(w.matches), "match": w.match_index}
+ if cmd in ("records-search", "records-search-step"):
+ app.show_records()
+ w = app.records_window
+ if cmd == "records-search":
+ w.search.set_text(arg)
+ w._searched(w.search) # now, not after SearchEntry's typing delay
+ else:
+ w.step(int(arg or "1"))
+ found = len(w._visible_sessions()) if w.query.strip() else None
+ r = {"ok": True, "query": w.query, "meetings": found, "shown": w.selected, "matches": len(w._matches),
+ "at": w.match_index + 1 if w._matches else 0, "line": w._current,
+ "bar": w.match_count.get_text() if w.match_bar.get_visible() else None}
+ Log.d("records search: \"%s\" %s meetings, shown %s matches=%d at=%s"
+ % (w.query, found, w.selected, len(w._matches), w._current or "-"))
+ return r
if cmd == "rename":
# `rename <id> <title>`; no title is 恢复自动标题.
sid, _, title = arg.partition(" ")
diff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.py
index 0f729fd..bc3b5bc 100644
--- a/linux/cicada/app/notes_window.py
+++ b/linux/cicada/app/notes_window.py
@@ -15,7 +15,7 @@ from gi.repository import Gdk, GLib, Gtk, Pango
from ..core import notes as notesmod
from ..core import problem
-from ..core import live_fixes, roommic, speakers
+from ..core import live_fixes, roommic, speakers, transcript_search
from ..core.strings import L, LF
from ..core.support import Log, clock
from . import ui, x11
@@ -455,16 +455,7 @@ class NotesWindow(Gtk.Window):
self._fill_transcript(scroll=True)
def _terms(self) -> list:
- """The query, plus every way the notes say that name was heard (江充 also finds 江松)."""
- q = self.query.strip()
- if not q:
- return []
- out = [q]
- for t in self.app.notes.notes.terms:
- forms = [t.name] + list(t.heard)
- if any(f and (q.lower() in f.lower() or f.lower() in q.lower()) for f in forms):
- out += [f for f in forms if f and f not in out]
- return out
+ return transcript_search.terms(self.query, self.app.notes.notes.terms)
def _fill_transcript(self, scroll: bool = False) -> None:
if not self.transcript_col.get_visible():
@@ -472,11 +463,10 @@ class NotesWindow(Gtk.Window):
session = self._session()
lines = session.lines if session else []
terms = self._terms()
- low = [t.lower() for t in terms]
def hit(l):
- return any(t in l.shown.lower() or t in (l.dst or "").lower() for t in low)
- self.matches = [l.id for l in lines if hit(l)] if terms else []
+ return transcript_search.line_matches(l, terms)
+ self.matches = transcript_search.matches(lines, terms)
if self.matches:
self.match_index %= len(self.matches)
current = self.matches[self.match_index] if self.matches else None
diff --git a/linux/cicada/app/records_window.py b/linux/cicada/app/records_window.py
index 8341cd8..d7998a0 100644
--- a/linux/cicada/app/records_window.py
+++ b/linux/cicada/app/records_window.py
@@ -11,7 +11,7 @@ from datetime import datetime, timedelta, timezone
from gi.repository import Gdk, Gio, GLib, Gtk, Pango
-from ..core import aac, roommic, session_store, speakers
+from ..core import aac, roommic, session_store, speakers, transcript_search
from ..core.strings import L, LF
from ..core.support import SOURCES, TARGETS, Log, clock
from . import share_dialog, ui
@@ -40,6 +40,10 @@ class RecordsWindow(Gtk.Window):
self.selected = None
self.pending_delete = None # a record deleted but still undoable
self.query = ""
+ # The search in the shown record (#33: a search opens the line, not just the meeting): its terms
+ # (misheard names too), the lines found, which one is being looked at.
+ self.match_index = 0
+ self._terms, self._matches, self._match_set, self._current = [], [], set(), None
self.mode = "both" # transcript: "both" or "dst"
self._both = False # the shown meeting has lines I said (同声传译): rows name 你 / 对方
self._nums, self._vnums, self._shown, self._speaker_key = {}, {}, {}, None # 说话人识别 on show
@@ -94,6 +98,10 @@ class RecordsWindow(Gtk.Window):
self.search = Gtk.SearchEntry()
self.search.set_placeholder_text(L("搜索标题和对话"))
self.search.connect("search-changed", self._searched)
+ # Enter goes to the next line found, as Ctrl+G does; Shift+Ctrl+G to the one before.
+ self.search.connect("activate", lambda *_: self.step(1))
+ self.search.connect("next-match", lambda *_: self.step(1))
+ self.search.connect("previous-match", lambda *_: self.step(-1))
ui.classes(self.search, "search")
# "Ctrl F" at the field's right end while it's empty, as the Mac shows ⌘F; the clear icon
# takes its place once something is typed.
@@ -108,6 +116,7 @@ class RecordsWindow(Gtk.Window):
self.search.connect("changed", lambda e: hint.set_visible(not e.get_text()))
ui.pad(search_box, 2, 10, 8, 10)
side.pack_start(search_box, False, False, 0)
+ side.pack_start(self._match_bar(), False, False, 0)
left_scroll = Gtk.ScrolledWindow()
left_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.list = Gtk.ListBox()
@@ -410,9 +419,10 @@ class RecordsWindow(Gtk.Window):
for s in self.app.store.all():
if s.id == self.pending_delete:
continue
- if q and q not in session_store.display_title(s).lower() and not any(
- q in l.shown.lower() or q in (l.dst or "").lower() for l in s.lines):
- continue
+ if q and q not in session_store.display_title(s).lower():
+ terms = transcript_search.terms(self.query, s.notes.terms if s.notes else [])
+ if not any(transcript_search.line_matches(l, terms) for l in s.lines):
+ continue
out.append(s)
return out
@@ -473,16 +483,79 @@ class RecordsWindow(Gtk.Window):
self.show_detail(empty=not everything, no_match=bool(everything) and not sessions)
def _searched(self, entry) -> None:
+ if entry.get_text() == self.query:
+ return # SearchEntry's delayed signal for text already searched: keep the line being looked at
self.query = entry.get_text()
+ self.match_index = 0
self.fill()
+ self._apply_search(scroll=True)
def _row_selected(self, _list, row) -> None:
if row is None or getattr(self, "_filling", False):
return
if row.session_id != self.selected:
self.selected = row.session_id
+ self.match_index = 0
self.show_detail()
self.right.get_vadjustment().set_value(0)
+ if self.query.strip():
+ self._apply_search(scroll=True)
+
+ # The search in the shown record
+
+ def _match_bar(self) -> Gtk.Widget:
+ """Where the search is in the shown record: 本场 2 / 7, and a way to the previous and next line."""
+ self.match_count = ui.text("", 12, "secondary", wrap=False, ellipsize=False)
+ bar = ui.hbox(2)
+ bar.pack_start(self.match_count, True, True, 0)
+ bar.pack_end(ui.icon_button("go-down-symbolic", L("下一个"), lambda: self.step(1), px=13, focus=False), False, False, 0)
+ bar.pack_end(ui.icon_button("go-up-symbolic", L("上一个"), lambda: self.step(-1), px=13, focus=False), False, False, 0)
+ ui.pad(bar, 0, 14, 6, 10)
+ bar.show_all()
+ bar.set_no_show_all(True)
+ bar.hide()
+ self.match_bar = bar
+ return bar
+
+ def _fill_match_bar(self) -> None:
+ on = bool(self.query.strip()) and bool(self._matches)
+ if on:
+ ui.retext(self.match_count, LF("本场 %lld / %lld", self.match_index + 1, len(self._matches)))
+ self.match_bar.set_visible(on)
+
+ def _search_state(self, s) -> None:
+ """The search's terms and the lines it finds in `s` (none while there is no query or record)."""
+ self._terms = transcript_search.terms(self.query, s.notes.terms if s.notes else []) if s is not None else []
+ self._matches = transcript_search.matches(s.lines, self._terms) if s is not None else []
+ self._match_set = set(self._matches)
+ if self._matches:
+ self.match_index = min(self.match_index, len(self._matches) - 1)
+ self._current = self._matches[self.match_index] if self._matches else None
+ self._fill_match_bar()
+
+ def step(self, d: int) -> None:
+ n = len(self._matches)
+ if not n:
+ return
+ self.match_index = (min(self.match_index, n - 1) + d + n) % n
+ self._apply_search(scroll=True)
+
+ def _apply_search(self, scroll: bool) -> None:
+ """Marks the shown record's lines for the search; with `scroll`, goes to the line being looked at."""
+ s = self.app.store.get(self.selected) if self.selected else None
+ if s is None or self.columns is None or getattr(self, "_sid", None) != s.id:
+ self._search_state(None)
+ return
+ self._search_state(s)
+ self._refresh_rows(s)
+ if not scroll or self._current is None:
+ return
+ idx = next(i for i, l in enumerate(s.lines) if l.id == self._current)
+ self._more_rows_until(idx + 1) # the batches may not have got that far yet
+ row = self._rows[idx][1]
+ # Once the rows just built are laid out, and again once a long page has its final height.
+ GLib.idle_add(lambda: self._centre(row) or False)
+ GLib.timeout_add(200, lambda: self._centre(row) or False)
# Detail
@@ -707,11 +780,14 @@ class RecordsWindow(Gtk.Window):
d.pack_end(ui.pad(hint, 0, 18, 14, 0), False, False, 0)
d.show_all()
return
+ if empty or no_match:
+ self._search_state(None)
if no_match:
d.pack_start(self._status_page("system-search-symbolic", LF("没有找到“%@”", self.query.strip()), "", []), True, True, 0)
d.show_all()
return
s = self.app.store.get(self.selected) if self.selected else None
+ self._search_state(s)
if s is None:
self._unload_player()
ui.clear(d)
@@ -837,6 +913,7 @@ class RecordsWindow(Gtk.Window):
ui.retext(self.pinned_title, session_store.display_title(s))
ui.retext(self.meta_label, self._meta(s, live))
self._fill_export_line(s, live)
+ self._search_state(s)
state = self._notes_state(s, live)
if state != self._notes_key:
self._notes_key = state
@@ -848,6 +925,12 @@ class RecordsWindow(Gtk.Window):
self.columns.reorder_child(new, 0)
new.show_all()
self._nums = speakers.numbers(s.lines) if self._vnums else {}
+ self._refresh_rows(s)
+ self._fill_fix_banner(s)
+ self._more_rows()
+
+ def _refresh_rows(self, s) -> None:
+ """Rebuilds the rows shown so far whose line, speaker label or search marks changed."""
starts = self._starts(s.lines)
for i, l in enumerate(s.lines[:len(self._rows)]):
if self._rows[i][0] != self._row_key(l, l.id in starts):
@@ -859,8 +942,6 @@ class RecordsWindow(Gtk.Window):
self.transcript.reorder_child(row, i + 1) # after the header
row.show_all()
self._rows[i] = (k, row)
- self._fill_fix_banner(s)
- self._more_rows()
# The recording (保存会议录音)
@@ -1326,7 +1407,9 @@ class RecordsWindow(Gtk.Window):
def _row_key(self, l, start):
fixes = tuple((f.from_, f.to, f.ask, f.off, f.user) for f in l.fixes or [])
- return (l.id, l.shown, l.dst, l.voice, start, fixes, self._editing == l.id)
+ # The search marks only lines it finds: typing a query doesn't rebuild the whole transcript.
+ found = (tuple(self._terms), l.id == self._current) if l.id in self._match_set else None
+ return (l.id, l.shown, l.dst, l.voice, start, fixes, self._editing == l.id, found)
def _who(self, l):
"""The label at a change of speaker, and its colour class."""
@@ -1523,16 +1606,19 @@ class RecordsWindow(Gtk.Window):
label = ui.hbox(6, label, ui.place_tag(l))
texts.pack_start(label, False, False, 0)
translated = l.dst and l.dst != l.shown
+ terms = self._terms if l.id in self._match_set else []
+ found = l.id == self._current
selectable = [] # the line's text: a drag over it selects, and must not play
if self._editing == l.id:
texts.pack_start(self._line_editor(l), False, False, 0)
else:
if translated:
- dst = ui.text(l.dst, 13, "ink", selectable=True, width_chars=46, lang=l.dstLang)
+ dst = ui.marked(l.dst, terms, 13, "ink", found, lang=l.dstLang, width_chars=46)
+ dst.set_selectable(True)
selectable.append(dst)
texts.pack_start(dst, False, False, 0)
if not translated or self.mode == "both":
- src = ui.fixed(l, 12 if translated else 13, "tertiary" if translated else "ink")
+ src = ui.fixed(l, 12 if translated else 13, "tertiary" if translated else "ink", terms, found)
src.set_selectable(True)
src.set_max_width_chars(46)
selectable.append(src)
diff --git a/linux/cicada/app/ui.py b/linux/cicada/app/ui.py
index 270fa4d..c24ac38 100644
--- a/linux/cicada/app/ui.py
+++ b/linux/cicada/app/ui.py
@@ -543,26 +543,14 @@ def retext(l: Gtk.Label, s: str) -> None:
l.set_markup('<span size="%d" lang="%s"%s>%s</span>' % (round(size * 768), lang, ' weight="bold"' if bold else "", esc(s)))
-def marked(s: str, terms: list, size: int = 13, cls: str = "ink", current: bool = False, lang: str | None = None) -> Gtk.Label:
+def marked(s: str, terms: list, size: int = 13, cls: str = "ink", current: bool = False, lang: str | None = None,
+ width_chars: int = 40) -> Gtk.Label:
"""text() with every search term highlighted in place (the current match in the accent)."""
- l = text(s, size, cls, lang=lang)
- low = s.lower()
- spans = []
- for t in terms:
- t = t.lower()
- i = low.find(t) if t else -1
- while i >= 0:
- spans.append((i, i + len(t)))
- i = low.find(t, i + len(t))
- if not spans:
+ from ..core.transcript_search import spans
+ l = text(s, size, cls, lang=lang, width_chars=width_chars)
+ merged = spans(s, terms)
+ if not merged:
return l
- spans.sort()
- merged = []
- for a, b in spans:
- if merged and a <= merged[-1][1]:
- merged[-1] = (merged[-1][0], max(b, merged[-1][1]))
- else:
- merged.append((a, b))
mark = ' background="#E8552B" foreground="#FFFFFF"' if current else ' background="#FBE0D5"'
out, at = [], 0
for a, b in merged:
@@ -575,13 +563,14 @@ def marked(s: str, terms: list, size: int = 13, cls: str = "ink", current: bool
return l
-def fixed(line, size: int = 13, cls: str = "ink", terms: list = (), current: bool = False, lang: str | None = None) -> Gtk.Label:
+def fixed(line, size: int = 13, cls: str = "ink", terms: list = (), current: bool = False, lang: str | None = None,
+ width_chars: int = 40) -> Gtk.Label:
"""A line as shown (改正听错的词): each fixed word underlined in grey (the Mac's dotted underline;
Pango has no dotted one), a word waiting for the user on a pale wash. While searching, the search
marks instead."""
from ..core.correction import apply
if terms or not line.fixes:
- return marked(line.shown, list(terms), size, cls, current, lang=lang or line.srcLang)
+ return marked(line.shown, list(terms), size, cls, current, lang=lang or line.srcLang, width_chars=width_chars)
s, marks = apply(line.fixes, line.src)
asks = []
for f in line.fixes:
@@ -599,7 +588,7 @@ def fixed(line, size: int = 13, cls: str = "ink", terms: list = (), current: boo
out.append("<span%s>%s</span>" % (attr, esc(s[a:b])))
at = b
out.append(esc(s[at:]))
- l = text(s, size, cls, lang=lang or line.srcLang)
+ l = text(s, size, cls, lang=lang or line.srcLang, width_chars=width_chars)
size_, lang_, bold = l.cicada_format
l.set_markup('<span size="%d" lang="%s"%s>%s</span>' % (round(size_ * 768), lang_, ' weight="bold"' if bold else "", "".join(out)))
return l
diff --git a/linux/cicada/core/transcript_search.py b/linux/cicada/core/transcript_search.py
new file mode 100644
index 0000000..697a66e
--- /dev/null
+++ b/linux/cicada/core/transcript_search.py
@@ -0,0 +1,55 @@
+"""Searching a meeting's lines, shared by the notes window and the records window, so a search finds
+the same lines (misheard names included) and marks them the same way in both (the Mac's
+TranscriptSearch.swift)."""
+from __future__ import annotations
+
+
+def terms(query: str, notes: list = ()) -> list:
+ """The query, plus every way the notes say that name was heard (江充 also finds 江松)."""
+ q = query.strip()
+ if not q:
+ return []
+ out = [q]
+ low = q.lower()
+ for t in notes or ():
+ forms = [t.name] + list(t.heard or [])
+ if any(f and (low in f.lower() or f.lower() in low) for f in forms):
+ out += [f for f in forms if f and f not in out]
+ return out
+
+
+def line_matches(line, terms_: list) -> bool:
+ low = [t.lower() for t in terms_ if t]
+ shown, dst = line.shown.lower(), (line.dst or "").lower()
+ return any(t in shown or t in dst for t in low)
+
+
+def matches(lines: list, terms_: list) -> list:
+ """The ids of the lines a search finds, in order."""
+ if not terms_:
+ return []
+ return [l.id for l in lines if line_matches(l, terms_)]
+
+
+def spans(text: str, terms_: list) -> list:
+ """Where each term is in `text` (case-insensitive), as merged (start, end) pairs: every occurrence
+ gets marked."""
+ low = text.lower()
+ found = []
+ for t in terms_:
+ t = t.lower()
+ # lower() can change a string's length (İ): then its offsets don't fit `text`, so leave it unmarked.
+ if not t or len(low) != len(text):
+ continue
+ i = low.find(t)
+ while i >= 0:
+ found.append((i, i + len(t)))
+ i = low.find(t, i + len(t))
+ found.sort()
+ merged = []
+ for a, b in found:
+ if merged and a <= merged[-1][1]:
+ merged[-1] = (merged[-1][0], max(b, merged[-1][1]))
+ else:
+ merged.append((a, b))
+ return merged
diff --git a/linux/scripts/cicadactl b/linux/scripts/cicadactl
index 42e8400..1a08372 100755
--- a/linux/scripts/cicadactl
+++ b/linux/scripts/cicadactl
@@ -4,6 +4,7 @@
target <code> | key-reload | windows | quit | dock [on|off] | close records
calls <program=name,…>|none|real | realcalls | endtimes <silence> <countdown> <grace>|off | endkeep
notes-tab notes|transcript | notes-search <text> | notes-wide on|off | onboarding-step <n> | settings-scroll <0-1>
+ records-search <text> | records-search-step 1|-1 (the records window's Ctrl+F search: meetings, matches, the line)
codecs | play [<seconds>] | pause | rate | playstate | follow | play-line <n> | line-rect <n>|pill | settings-general (保存会议录音 and its player)
fixes on|off | heard <text> | fix-state | fix-answer yes|no | fix-later | fix-revert <line> | fix-undo
fix-edit <line>=<text>[|one][|keep0] | fix-editor <line>=<text> | vocab-add <word>=<heard>[|…] | vocab-state
diff --git a/linux/tests/test_transcript_search.py b/linux/tests/test_transcript_search.py
new file mode 100644
index 0000000..cad3e9d
--- /dev/null
+++ b/linux/tests/test_transcript_search.py
@@ -0,0 +1,51 @@
+"""The search in a meeting's lines, shared by the notes window and the records window (the Mac's
+TranscriptSearchTests)."""
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.dirname(HERE))
+
+from cicada.core import transcript_search as ts # noqa: E402
+from cicada.core.models import NoteTerm, TranscriptLine # noqa: E402
+
+
+def line(id_, src, dst=None):
+ return TranscriptLine(id=id_, t=0, speaker="them", src=src, dst=dst, srcLang="zh-CN", dstLang="en")
+
+
+class TranscriptSearchTests(unittest.TestCase):
+ def test_a_name_also_finds_how_it_was_misheard(self):
+ notes = [NoteTerm(name="江充", note="", heard=["江松"]), NoteTerm(name="Ling", note="", heard=[])]
+ self.assertEqual(ts.terms("江充", notes), ["江充", "江松"])
+ # Searching the misheard form finds the right one too; an unrelated term stays out.
+ self.assertEqual(ts.terms(" 江松 ", notes), ["江松", "江充"])
+ self.assertEqual(ts.terms(" ", notes), [])
+ # A query inside a name, and a name inside the query, both bring the forms in, case aside.
+ self.assertEqual(ts.terms("ling", notes), ["ling", "Ling"])
+ self.assertEqual(ts.terms("问江充吧", notes), ["问江充吧", "江充", "江松"])
+
+ def test_matches_look_in_both_languages_in_order(self):
+ lines = [line("a", "我们看一下预算"), line("b", "下周再说", "the budget next week"), line("c", "好的")]
+ self.assertEqual(ts.matches(lines, ["预算"]), ["a"])
+ self.assertEqual(ts.matches(lines, ["BUDGET"]), ["b"])
+ self.assertEqual(ts.matches(lines, ["预算", "budget"]), ["a", "b"])
+ self.assertEqual(ts.matches(lines, []), [])
+
+ def test_a_misheard_name_is_found_in_the_meeting(self):
+ notes = [NoteTerm(name="江充", note="", heard=["江松"])]
+ lines = [line("a", "江松说了"), line("b", "没有"), line("c", "问江充")]
+ self.assertEqual(ts.matches(lines, ts.terms("江充", notes)), ["a", "c"])
+
+ def test_every_occurrence_is_marked(self):
+ self.assertEqual(ts.spans("Budget, budget, done", ["budget"]), [(0, 6), (8, 14)])
+ # Overlapping terms mark one stretch.
+ self.assertEqual(ts.spans("江充江松", ["江充", "充江"]), [(0, 3)])
+ self.assertEqual(ts.spans("nothing", ["budget"]), [])
+
+
+if __name__ == "__main__":
+ unittest.main()