知了 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
fix: searching the records with ⌘F opens the meeting at the line found and highlights it
wquguru3532b1a6d6d9
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex fa39caa..9a9f12c 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -1654,3 +1654,4 @@/* iOS: playback */"播放进度" = "Playback position";+"本场 %lld / %lld" = "This meeting %lld / %lld";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex bd0e447..9b35139 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -1654,3 +1654,4 @@/* iOS: playback */"播放进度" = "再生位置";+"本场 %lld / %lld" = "この会議 %lld / %lld";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 6b30414..eb866ed 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -1654,3 +1654,4 @@/* iOS: playback */"播放进度" = "재생 위치";+"本场 %lld / %lld" = "이 회의 %lld / %lld";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex 5d021ba..ad79c83 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -1559,3 +1559,4 @@/* iOS: playback */"播放进度" = "播放进度";+"本场 %lld / %lld" = "本场 %lld / %lld";diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 58b9656..ea732ba 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -2342,6 +2342,11 @@ final class AppModel: ObservableObject {try? png.write(to: URL(fileURLWithPath: arg))}case "mainShow": mainShow = arg+ case "mainSearch":+ // Types into the records window's search (⌘F); mainSearchStep:<1|-1> is Return / the arrows.+ NotificationCenter.default.post(name: .debugMainSearch, object: arg)+ case "mainSearchStep":+ NotificationCenter.default.post(name: .debugMainSearch, object: Int(arg) ?? 1)case "play":// The shown record plays from <seconds>, as a click on a line's time does.if let t = Double(arg) { NotificationCenter.default.post(name: .debugPlay, object: t) }diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex 2ffad00..2f69ecb 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -897,25 +897,14 @@ struct TranscriptListView<Partial: View>: View, Equatable {.transition(.opacity)}- private func matches(_ l: TranscriptLine) -> Bool {- terms.contains { l.shown.localizedCaseInsensitiveContains($0) || (l.dst ?? "").localizedCaseInsensitiveContains($0) }- }+ private func matches(_ l: TranscriptLine) -> Bool { TranscriptSearch.matches(l, terms) }private func highlighted(_ text: String, current: Bool) -> AttributedString {- highlighted(AttributedString(text), current: current)+ TranscriptSearch.highlighted(AttributedString(text), terms, current: current)}private func highlighted(_ base: AttributedString, current: Bool) -> AttributedString {- var a = base- for term in terms where !term.isEmpty {- var from = a.startIndex- while from < a.endIndex, let r = a[from...].range(of: term, options: .caseInsensitive) {- a[r].backgroundColor = current ? Palette.accent : Palette.accentPale- a[r].foregroundColor = current ? .white : Palette.accentInk- from = r.upperBound- }- }- return a+ TranscriptSearch.highlighted(base, terms, current: current)}private func row(_ ls: [TranscriptLine], label: Bool = true) -> some View {diff --git a/Sources/Cicada/NotesWindow.swift b/Sources/Cicada/NotesWindow.swiftindex 45e5183..384c2a0 100644--- a/Sources/Cicada/NotesWindow.swift+++ b/Sources/Cicada/NotesWindow.swift@@ -462,27 +462,9 @@ struct NotesWindowView: View {.overlay(RoundedRectangle(cornerRadius: 10).stroke(searchFocused ? Palette.accent : .clear, lineWidth: 1.5))}- /// The query, plus every way the notes say that name was heard (江充 also finds 江松).- private var searchTerms: [String] {- let q = query.trimmingCharacters(in: .whitespaces)- guard !q.isEmpty else { return [] }- var out = [q]- for t in engine.notes.terms {- let forms = [t.name] + t.heard- if forms.contains(where: { $0.localizedCaseInsensitiveContains(q) || q.localizedCaseInsensitiveContains($0) }) {- out += forms.filter { !out.contains($0) }- }- }- return out- }+ private var searchTerms: [String] { TranscriptSearch.terms(query, notes: engine.notes.terms) }- private var matches: [String] {- let terms = searchTerms- guard !terms.isEmpty else { return [] }- return (session?.lines ?? []).filter { l in- terms.contains { l.shown.localizedCaseInsensitiveContains($0) || (l.dst ?? "").localizedCaseInsensitiveContains($0) }- }.map(\.id)- }+ private var matches: [String] { TranscriptSearch.matches(session?.lines ?? [], searchTerms) }private var currentIndex: Int { matches.isEmpty ? 0 : min(matchIndex, matches.count - 1) }diff --git a/Sources/Cicada/TranscriptSearch.swift b/Sources/Cicada/TranscriptSearch.swiftnew file mode 100644index 0000000..a0e9f13--- /dev/null+++ b/Sources/Cicada/TranscriptSearch.swift@@ -0,0 +1,43 @@+import SwiftUI++/// Searching a meeting's lines, shared by the notes window and the main window's records, so a+/// search finds the same lines (misheard names included) and marks them the same way in both.+enum TranscriptSearch {+ /// The query, plus every way the notes say that name was heard (江充 also finds 江松).+ static func terms(_ query: String, notes: [NoteTerm]) -> [String] {+ let q = query.trimmingCharacters(in: .whitespaces)+ guard !q.isEmpty else { return [] }+ var out = [q]+ for t in notes {+ let forms = [t.name] + t.heard+ if forms.contains(where: { $0.localizedCaseInsensitiveContains(q) || q.localizedCaseInsensitiveContains($0) }) {+ out += forms.filter { !$0.isEmpty && !out.contains($0) }+ }+ }+ return out+ }++ static func matches(_ l: TranscriptLine, _ terms: [String]) -> Bool {+ terms.contains { l.shown.localizedCaseInsensitiveContains($0) || (l.dst ?? "").localizedCaseInsensitiveContains($0) }+ }++ /// The ids of the lines a search finds, in order.+ static func matches(_ lines: [TranscriptLine], _ terms: [String]) -> [String] {+ guard !terms.isEmpty else { return [] }+ return lines.filter { matches($0, terms) }.map(\.id)+ }++ /// Every term marked in place; the match being looked at stands out from the rest.+ static func highlighted(_ base: AttributedString, _ terms: [String], current: Bool) -> AttributedString {+ var a = base+ for term in terms where !term.isEmpty {+ var from = a.startIndex+ while from < a.endIndex, let r = a[from...].range(of: term, options: .caseInsensitive) {+ a[r].backgroundColor = current ? Palette.accent : Palette.accentPale+ a[r].foregroundColor = current ? .white : Palette.accentInk+ from = r.upperBound+ }+ }+ return a+ }+}diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swiftindex dd1d1de..24756b1 100644--- a/Sources/Cicada/Views.swift+++ b/Sources/Cicada/Views.swift@@ -822,6 +822,8 @@ struct MainWindowView: View {@State private var dropping = false@State private var selection: String?@State private var query = ""+ /// Which of the shown record's matches the search is on (#33: a search opens the line, not just the meeting).+ @State private var matchIndex = 0@State private var view = "both"@State private var tab = "notes"@State private var jumpTo: Double?@@ -849,11 +851,31 @@ struct MainWindowView: View {private var filtered: [Session] {guard !query.isEmpty else { return store.sessions }return store.sessions.filter { s in- s.displayTitle.localizedCaseInsensitiveContains(query)- || s.lines.contains { $0.shown.localizedCaseInsensitiveContains(query) || ($0.dst ?? "").localizedCaseInsensitiveContains(query) }+ let terms = TranscriptSearch.terms(query, notes: s.notes?.terms ?? [])+ return s.displayTitle.localizedCaseInsensitiveContains(query) || s.lines.contains { TranscriptSearch.matches($0, terms) }}}+ /// The search in the shown record: its terms (misheard names too), the lines found, the one being looked at.+ private var searchTerms: [String] { TranscriptSearch.terms(query, notes: current?.notes?.terms ?? []) }+ private var matches: [String] { TranscriptSearch.matches(current?.lines ?? [], searchTerms) }+ private var currentMatch: String? {+ let ms = matches+ return ms.isEmpty ? nil : ms[min(matchIndex, ms.count - 1)]+ }++ private func step(_ d: Int) {+ let n = matches.count+ guard n > 0 else { return }+ matchIndex = (min(matchIndex, n - 1) + d + n) % n+ }++ /// A search that finds lines in the shown record opens its transcript at the first one.+ private func showMatches() {+ matchIndex = 0+ if !matches.isEmpty, let s = current, importer.status(of: s) == nil { tab = "transcript" }+ }+private var current: Session? { store.session(selection ?? store.sessions.first?.id) }/// The shown record's audio: an imported file, or the meeting's own recording once it has ended.@@ -888,6 +910,8 @@ struct MainWindowView: View {} isTargeted: { dropping = $0 }.overlay { if dropping { ImportDropOverlay() } }.onChange(of: current?.id, initial: true) { _, _ in loadPlayer() }+ .onChange(of: query) { _, _ in showMatches() }+ .onChange(of: selection) { _, _ in if !query.isEmpty { showMatches() } }// A meeting that ends while it is shown, and its recording once it is rewrapped into an .m4a..onChange(of: store.liveID) { _, _ in loadPlayer() }// Opened afresh: a file opened before the room was mixed in (#19) would play one side only.@@ -901,6 +925,13 @@ struct MainWindowView: View {}}.onDisappear { wordClick.remove() }+ .onReceive(NotificationCenter.default.publisher(for: .debugMainSearch)) { n in+ if let text = n.object as? String { query = text } else if let d = n.object as? Int { step(d) }+ DispatchQueue.main.async {+ debugLog("main search: \"\(query)\" \(filtered.count) meetings, shown \(current?.id ?? "-") tab=\(tab) "+ + "matches=\(matches.count) at=\(currentMatch ?? "-")")+ }+ }.onReceive(NotificationCenter.default.publisher(for: .debugPlay)) { n inif let t = n.object as? Double { player.play(from: t) }}@@ -925,6 +956,7 @@ struct MainWindowView: View {HStack(spacing: 8) {Image(systemName: "magnifyingglass").foregroundStyle(Palette.secondary)TextField("搜索", text: $query).textFieldStyle(.plain).focused($searchFocused)+ .onSubmit { step(1) }if query.isEmpty {Text("⌘F").font(.system(size: 11)).foregroundStyle(Palette.secondary)} else {@@ -934,7 +966,8 @@ struct MainWindowView: View {}.font(.system(size: 13)).padding(.horizontal, 12).frame(height: 30)- .padding(.bottom, 6)+ .padding(.bottom, query.isEmpty || matches.isEmpty ? 6 : 0)+ if !query.isEmpty, !matches.isEmpty { matchBar }ScrollView {LazyVStack(alignment: .leading, spacing: 2) {@@ -976,6 +1009,27 @@ struct MainWindowView: View {}}+ /// Where the search is in the shown record: 本场 2 / 7, and a way to the previous and next line.+ private var matchBar: some View {+ let n = matches.count+ return HStack(spacing: 2) {+ Text("本场 \(min(matchIndex, n - 1) + 1) / \(n)")+ .font(.system(size: 12).monospacedDigit()).foregroundStyle(Palette.secondary)+ Spacer(minLength: 4)+ matchButton("chevron.up", help: L("上一个")) { step(-1) }+ matchButton("chevron.down", help: L("下一个")) { step(1) }+ }+ .padding(.leading, 12).padding(.trailing, 6).padding(.bottom, 6)+ }++ private func matchButton(_ icon: String, help: String, action: @escaping () -> Void) -> some View {+ Button(action: action) {+ Image(systemName: icon).font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)+ .frame(width: 24, height: 22).contentShape(Rectangle())+ }+ .buttonStyle(.plain).help(help).accessibilityLabel(help)+ }+private func sessionRow(_ s: Session) -> some View {let selected = s.id == (selection ?? store.sessions.first?.id)let live = s.id == store.liveID@@ -1406,6 +1460,8 @@ struct MainWindowView: View {let starts = SpeakerLabels.runStarts(s.lines, speakers).union(both ? RecordList.placeStarts(s.lines) : [])let voices = SpeakerLabels.voiceNumbers(s)let playingLine = player.lineID(in: s)+ let terms = searchTerms+ let found = currentMatchif s.id != store.liveID {FixReviewBanner(fixes: model.fixes, session: s, onShow: { id in withAnimation { proxy.scrollTo(id, anchor: .center) } },onEdit: { l, suggestion in editingStart = suggestion; editingLine = l.id; proxy.scrollTo(l.id, anchor: .center) })@@ -1413,7 +1469,7 @@ struct MainWindowView: View {}ForEach(s.lines) { l inlineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || settings.speakerEveryLine || starts.contains(l.id), voices: !speakers.isEmpty, place: both, in: s,- current: l.id == playingLine)+ current: l.id == playingLine, terms: terms, found: l.id == found).contextMenu {Button(L("改这句…")) { editingStart = l.shown; editingLine = l.id }if !speakers.isEmpty, l.speaker == "them" { assignMenu(s, l, voices) }@@ -1473,14 +1529,22 @@ struct MainWindowView: View {withAnimation { proxy.scrollTo(id, anchor: .center) }}}+ .onChange(of: currentMatch) { _, id in+ if let id { withAnimation { proxy.scrollTo(id, anchor: .center) } }+ }.onAppear {if let t = jumpTo, let l = s.lines.first(where: { $0.t >= t - 1 }) { proxy.scrollTo(l.id, anchor: .top) }+ else if let id = currentMatch {+ // Opened by a search: the lazy list needs a moment to lay out before it can go to the line found.+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { proxy.scrollTo(id, anchor: .center) }+ }jumpTo = nil}}}- private func lineRow(_ l: TranscriptLine, speaker: Int? = nil, label: Bool = true, voices: Bool = false, place: Bool = false, in shownSession: Session? = nil, current: Bool = false) -> some View {+ private func lineRow(_ l: TranscriptLine, speaker: Int? = nil, label: Bool = true, voices: Bool = false, place: Bool = false, in shownSession: Session? = nil, current: Bool = false,+ terms: [String] = [], found: Bool = false) -> some View {let me = l.speaker == "me"let playable = shownSession.map { player.sessionID == $0.id && player.ready } ?? falselet hovered = playable && hoveredLine == l.id && editingLine != l.id@@ -1550,14 +1614,14 @@ struct MainWindowView: View {if editingLine == l.id, let s = shownSession {LineEditor(line: l, session: s.id, fixes: model.fixes, start: editingStart) { editingLine = nil }} else if view != "dst" {- Text(TranscriptParagraphs.joinFixed([l]))+ Text(TranscriptSearch.highlighted(TranscriptParagraphs.joinFixed([l]), terms, current: found)).font(.system(size: view == "src" ? 15 : 13)).foregroundStyle(view == "src" ? Palette.ink : Palette.tertiary).lineSpacing(2).textSelection(.enabled)}if view != "src" {- Text(l.dst ?? L("翻译中…"))+ Text(l.dst.map { TranscriptSearch.highlighted(AttributedString($0), terms, current: found) } ?? AttributedString(L("翻译中…"))).font(.system(size: 15)).lineSpacing(3).foregroundStyle(l.dst == nil ? Palette.tertiary : Palette.ink).textSelection(.enabled)@@ -1866,6 +1930,7 @@ struct LanguageNotice: View {extension Notification.Name {/// Debug `play:<seconds>`: the shown record plays from there.static let debugPlay = Notification.Name("cicada.debugPlay")+ static let debugMainSearch = Notification.Name("cicada.debugMainSearch")/// Debug `shareSheet:<id>`: the 分享… sheet opens for that record (no id: it closes).static let debugShareSheet = Notification.Name("cicada.debugShareSheet")}diff --git a/Tests/CicadaTests/TranscriptSearchTests.swift b/Tests/CicadaTests/TranscriptSearchTests.swiftnew file mode 100644index 0000000..292967b--- /dev/null+++ b/Tests/CicadaTests/TranscriptSearchTests.swift@@ -0,0 +1,31 @@+import Foundation+import Testing+@testable import Cicada++@Suite struct TranscriptSearchTests {+ private func line(_ id: String, _ src: String, _ dst: String? = nil) -> TranscriptLine {+ TranscriptLine(id: id, t: 0, speaker: "them", src: src, dst: dst, srcLang: "zh-CN", dstLang: "en")+ }++ @Test func aNameAlsoFindsHowItWasMisheard() {+ let notes = [NoteTerm(name: "江充", note: "", heard: ["江松"]), NoteTerm(name: "Ling", note: "", heard: [])]+ #expect(TranscriptSearch.terms("江充", notes: notes) == ["江充", "江松"])+ // Searching the misheard form finds the right one too; an unrelated term stays out.+ #expect(TranscriptSearch.terms(" 江松 ", notes: notes) == ["江松", "江充"])+ #expect(TranscriptSearch.terms(" ", notes: notes).isEmpty)+ }++ @Test func matchesLookInBothLanguagesInOrder() {+ let lines = [line("a", "我们看一下预算"), line("b", "下周再说", "the budget next week"), line("c", "好的")]+ #expect(TranscriptSearch.matches(lines, ["预算"]) == ["a"])+ #expect(TranscriptSearch.matches(lines, ["BUDGET"]) == ["b"])+ #expect(TranscriptSearch.matches(lines, ["预算", "budget"]) == ["a", "b"])+ #expect(TranscriptSearch.matches(lines, []).isEmpty)+ }++ @Test func everyOccurrenceIsMarked() {+ let a = TranscriptSearch.highlighted(AttributedString("Budget, budget, done"), ["budget"], current: false)+ let marked = a.runs.filter { $0.backgroundColor != nil }.map { String(a[$0.range].characters) }+ #expect(marked == ["Budget", "budget"])+ }+}diff --git a/site/changelog.json b/site/changelog.jsonindex 9d9b4dc..8a990c5 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -13,6 +13,14 @@],"title": "Mac 版有了正式签名并通过 Apple 公证,第一次打开不会再被系统拦下。","text": "以前第一次打开要去 系统设置 › 隐私与安全性 里点“仍要打开”,现在双击就能打开。已经装好的知了照常自动更新,之前开过的权限都还在,不用重新授权。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "mac"+ ],+ "title": "会议记录里按 ⌘F 搜索,点开会议会直接跳到找到的那句并高亮。",+ "text": "以前只会筛出会议列表。现在会打开文字记录、标出每一处,左侧显示“本场 1 / 3”,按回车或上下箭头逐个跳;识别错的同音名字也一起找到。"}]},diff --git a/tools/README.md b/tools/README.mdindex c52268e..e30bc37 100644--- a/tools/README.md+++ b/tools/README.md@@ -29,7 +29,7 @@- 显示与字幕:`display:<notes|bar|none>`、`subtitles:<both|translation|original>`、`meetingSubtitles:<…>`、`overlayState`、`overlayToggle`、`pillClick`(等于点主窗口顶部的“正在听”)、`overlayAuto[:off]`、`hideAfter:<秒>`- 纪要:`notesLang:<mine|source>`、`meetingNotesLang:<…>`、`notesRegenerate:<id>=<mine|source>`、`notesWindow[:x,y,w,h]`、`notesClose`、`notesMinimize`、`notesFrame`、`notesNow`、`notesState`、`notesShow:<id>`、`notesReplay:<id>[,<每次几句>]`(按会议时的节奏重写一遍纪要,默认每次 4 句;回复被 max_tokens 截断时日志写 `cut at max_tokens`)、`notesCapturable[:off]`(只改窗口能否被截屏)、`notesShare:<on|off>`(改“共享屏幕时让对方看到”这个设置,等于点图标或开关)- 结束会议:`endSim:<应用名>[,…]` 假装这些会议应用在通话(`endSim:` 全部挂断,`endSim:off` 回到真实情况),`endTimes:<静默秒>,<倒计时秒>,<挂断宽限秒>` 缩短等待(`endTimes:` 回到设置),`endKeep` 等于点“继续记录”,`endState` 写进日志- - 渲染(不需要录屏权限):`panelRender:<png>`(菜单栏面板,离屏画)、`windowsRender:<目录>`、`settingsRender:<栏目>=<png>`、`notesRender:<png>`、`mainShow:<id>[,transcript]`、`mainWindow:x,y,宽,高`(摆好主窗口并暂时浮在最上层,方便模拟点击;不带参数恢复)、`mainRender:<png>`、`speakTestRender:<png>`;`peopleShow`(人员库)单独开成窗口,用 `winall` + `screencapture -l` 截;纪要原地编辑:`noteEdit:<会议 id>=<summary|N>` 打开一处(N 按结论再待办从 1 数,`noteEdit:` 收起),`noteSave:<会议 id>=<summary|N>|<文字>[|<负责人>]` 等于回车保存,文字为空就删掉这条+ - 渲染(不需要录屏权限):`panelRender:<png>`(菜单栏面板,离屏画)、`windowsRender:<目录>`、`settingsRender:<栏目>=<png>`、`notesRender:<png>`、`mainShow:<id>[,transcript]`、`mainSearch:<文字>`(在会议记录的 ⌘F 搜索框里输入,日志 `main search:` 写出找到几场、本场几处、停在哪句)、`mainSearchStep:<1|-1>`(回车 / 上下箭头)、`mainWindow:x,y,宽,高`(摆好主窗口并暂时浮在最上层,方便模拟点击;不带参数恢复)、`mainRender:<png>`、`speakTestRender:<png>`;`peopleShow`(人员库)单独开成窗口,用 `winall` + `screencapture -l` 截;纪要原地编辑:`noteEdit:<会议 id>=<summary|N>` 打开一处(N 按结论再待办从 1 数,`noteEdit:` 收起),`noteSave:<会议 id>=<summary|N>|<文字>[|<负责人>]` 等于回车保存,文字为空就删掉这条- AI:`aiKeyFile:<路径>`(从 0600 文件读 key,不经过日志;测完就删掉文件)、`aiCheck`、`aiRemove`、`aiHide:<on|off>`(只在内存里当作没有 key,文件不动;用于截图)、`aiState`、`lingSimulate:<429|hijack|timeout|off>`、`translateFail:<n>`(接下来 n 句在所有翻译来源都失败,用来测重试)、`googleDown:<on|off>`(Google 翻译当作连不上,测提示和暂停)- 声音:`voice:<语言>[=<id>]`、`voicePreview:<语言>=<id>`、`voiceCloneFile:<wav>`、`voicePicker:<on|off>`- 诊断:`diagnostics:<on|off>`、`diagReport`