知了 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: Rename speakers, merge them or give a paragraph to someone else right in the live notes window
wqugurub3e09a9cbdd5
diff --git a/README.en.md b/README.en.mdindex 69006dd..102fdf2 100644--- a/README.en.md+++ b/README.en.md@@ -54,7 +54,7 @@ Hold the right `⌥` key and speak so the room hears your translated voice throu### Meeting records-Every session saves its bilingual transcript, notes, and audio recording on your Mac, and turning on experimental speaker identification separates voices on the other side and fills in their names when a Ling key is set. Cicada ends the session and trims the silent tail when the call hangs up or after 10 minutes of silence, and you can generate notes later or export to Markdown, Word, or SRT subtitles. Right now "you" in the transcript covers only what you say while holding the talk key; recording what you say directly into the meeting is on the [roadmap](#roadmap).+Every session saves its bilingual transcript, notes, and audio recording on your Mac, speaker identification separates voices on the other side and fills in their names when a Ling key is set; if it gets someone wrong, rename, merge, or reassign a passage right in the live notes window. Cicada ends the session and trims the silent tail when the call hangs up or after 10 minutes of silence, and you can generate notes later or export to Markdown, Word, or SRT subtitles. Drop an existing recording or video on the records window (or use File › Import Recording or Video…) and it is transcribed on your Mac, much faster than real time, into a bilingual record; click a line's time to play the original file from there. Right now "you" in the transcript covers only what you say while holding the talk key; recording what you say directly into the meeting is on the [roadmap](#roadmap).<p align="center"><img src="docs/records.png" width="640" alt="Meeting records window showing identified speakers and a line-by-line English and Chinese transcript">diff --git a/README.md b/README.mdindex 1bb887e..b39951e 100644--- a/README.md+++ b/README.md@@ -54,7 +54,7 @@### 会议记录-每场会议的双语文字记录、纪要和原始录音都保存在本机,打开实验性的说话人识别后还能区分对方不同的说话人并在有 Ling key 时填上名字。会议软件挂断或 10 分钟没人说话时会自动结束并截掉空白,会后随时可以补生成纪要,或导出成 Markdown、Word 和 SRT 字幕。目前记录里的你只包含按住说话键说的话,会上直接开口的部分见[路线图](#路线图)。+每场会议的双语文字记录、纪要和原始录音都保存在本机,还能按声音区分对方不同的说话人并在有 Ling key 时填上名字,认错了在实时纪要窗口里就能改名、合并或把某段话改给别人。会议软件挂断或 10 分钟没人说话时会自动结束并截掉空白,会后随时可以补生成纪要,或导出成 Markdown、Word 和 SRT 字幕。已有的录音或视频也能拖进会议记录窗口(或用“文件 › 导入录音或视频…”),在本机比实时快得多地转成一场双语记录,点时间就从那一句开始播放原文件。目前记录里的你只包含按住说话键说的话,会上直接开口的部分见[路线图](#路线图)。<p align="center"><img src="docs/records.png" width="640" alt="会议记录窗口,显示识别出的说话人名字和逐句英中双语文字记录">diff --git a/Sources/LiveSubs/AppModel.swift b/Sources/LiveSubs/AppModel.swiftindex 5b03269..004ef82 100644--- a/Sources/LiveSubs/AppModel.swift+++ b/Sources/LiveSubs/AppModel.swift@@ -115,8 +115,8 @@ final class AppModel: ObservableObject {let sample = SamplePlayer()let speakers = SpeakerTagger()lazy var speakerNamer = SpeakerNamer(ling: ling, store: store)- /// Set by the notes window; the records window's people row opens that voice's editor.- @Published var speakerEdit: SpeakerEditRequest?+ /// The last speaker edit, offered as 撤销 at the bottom of both windows for a few seconds.+ @Published var speakerUndo: SpeakerUndo?private var speakerSetting: AnyCancellable?var openOnboarding: (() -> Void)?@@ -986,12 +986,54 @@ final class AppModel: ObservableObject {// MARK: Meeting record- /// Names are typed in the records window: the notes window never takes focus.- func editSpeaker(session: String, voice: Int) {- speakerEdit = SpeakerEditRequest(session: session, voice: voice)- mainShow = nil- mainShow = "\(session),transcript"- openMainWindow?()+ // MARK: Speakers++ /// Name a voice ("" keeps 说话人 N, nil goes back to Ling's guess).+ func renameSpeaker(session id: String, voice: Int, _ name: String?) {+ guard let s = store.session(id) else { return }+ let n = SpeakerLabels.voiceNumbers(s.lines)[voice] ?? 0+ let before = SpeakerLabels.label(n, SpeakerLabels.names(s))+ speakerEdit(id) { store.setVoiceName(id, voice: voice, name) }+ let after = store.session(id).map { SpeakerLabels.label(n, SpeakerLabels.names($0)) } ?? before+ if after != before { speakerUndo?.text = L("\(before) 已改成 \(after)") } else { speakerUndo = nil }+ }++ /// Two voices are one person. While listening the voiceprints merge too, which 撤销 can't take back.+ func mergeSpeaker(session id: String, _ from: Int, into: Int) {+ guard let s = store.session(id) else { return }+ let numbers = SpeakerLabels.voiceNumbers(s.lines), names = SpeakerLabels.names(s)+ let a = SpeakerLabels.label(numbers[from] ?? 0, names), b = SpeakerLabels.label(numbers[into] ?? 0, names)+ speakerEdit(id) { store.mergeVoice(id, from, into: into) }+ if id == store.liveID { speakers.merge(from, into: into) }+ speakerUndo?.text = L("\(a) 已并入 \(b)")+ }++ /// These lines were someone else's.+ func assignLines(session id: String, _ lines: Set<String>, to voice: Int) {+ guard let s = store.session(id) else { return }+ let first = s.lines.first { lines.contains($0.id) }+ speakerEdit(id) { store.setLineVoices(id, lines: lines, voice) }+ guard let s2 = store.session(id) else { return }+ let who = SpeakerLabels.label(SpeakerLabels.voiceNumbers(s2.lines)[voice] ?? 0, SpeakerLabels.names(s2))+ speakerUndo?.text = L("\(first.map { TranscriptExport.clock($0.t) } ?? "") 这句已改给 \(who)")+ }++ func undoSpeakerEdit() {+ guard let u = speakerUndo else { return }+ speakerUndo = nil+ store.restore(u.session, u.snapshot)+ debugLog("speakers: undo \(u.session)")+ }++ private func speakerEdit(_ id: String, _ change: () -> Void) {+ guard let snap = store.voiceSnapshot(id) else { return }+ change()+ let undo = SpeakerUndo(session: id, snapshot: snap, text: "")+ speakerUndo = undo+ debugLog("speakers: edit \(id)")+ DispatchQueue.main.asyncAfter(deadline: .now() + 6) { [weak self] in+ if self?.speakerUndo?.id == undo.id { self?.speakerUndo = nil }+ }}private func recordHeard(_ seg: Segment, duration: Double) {diff --git a/Sources/LiveSubs/Notes.swift b/Sources/LiveSubs/Notes.swiftindex 9ac62ef..5c911dd 100644--- a/Sources/LiveSubs/Notes.swift+++ b/Sources/LiveSubs/Notes.swift@@ -68,6 +68,16 @@ struct NoteTerm: Codable, Equatable, Identifiable {static func ordered(_ terms: [NoteTerm]) -> [NoteTerm] {terms.filter { !$0.heard.isEmpty } + terms.filter { $0.heard.isEmpty }}++ /// Roles that say a term is a person, for offering it as a speaker's name.+ private static let roles = ["首席", "执行官", "主席", "总裁", "董事", "经理", "创始人", "记者", "主持", "研究员",+ "分析师", "教授", "老师", "教师", "官员", "部长", "议员", "候选人", "嘉宾", "发言人",+ "CEO", "CFO", "CTO", "host", "analyst", "reporter", "founder"]++ /// Names of people the notes mention, by their note ("BGN 集团首席运营官").+ static func people(_ terms: [NoteTerm]) -> [String] {+ terms.filter { t in roles.contains { t.note.localizedCaseInsensitiveContains($0) } }.map(\.name)+ }}// MARK: - Enginediff --git a/Sources/LiveSubs/NotesViews.swift b/Sources/LiveSubs/NotesViews.swiftindex d937dd7..abccb71 100644--- a/Sources/LiveSubs/NotesViews.swift+++ b/Sources/LiveSubs/NotesViews.swift@@ -498,7 +498,7 @@ struct TranscriptListView<Partial: View>: View, Equatable {/// `partial` is on show (`TranscriptPartial.shows`).var partialShown = falsevar jumpTo: Double?- /// Experimental: line id → speaker number for the other side's lines (SpeakerLabels).+ /// Line id → speaker number for the other side's lines (SpeakerLabels).var speakers: [String: Int] = [:]/// When listening began, for the start mark shown before the first line.var startedAt: Date?@@ -511,6 +511,8 @@ struct TranscriptListView<Partial: View>: View, Equatable {var onAssign: ((Set<String>, Int) -> Void)?@ViewBuilder var partial: Partial+ @State private var assigning: String?+@State private var following = true@State private var seenCount = 0@State private var followQueued = false@@ -518,7 +520,8 @@ struct TranscriptListView<Partial: View>: View, Equatable {static func == (a: Self, b: Self) -> Bool {a.lines == b.lines && a.topics == b.topics && a.terms == b.terms && a.currentMatch == b.currentMatch&& a.bilingual == b.bilingual && a.live == b.live && a.partialShown == b.partialShown- && a.jumpTo == b.jumpTo && a.speakers == b.speakers && a.startedAt == b.startedAt+ && a.jumpTo == b.jumpTo && a.speakers == b.speakers && a.startedAt == b.startedAt && a.voices == b.voices && a.marked == b.marked+ && a.identifying == b.identifying}private var searching: Bool { !terms.isEmpty }@@ -731,6 +734,18 @@ struct TranscriptListView<Partial: View>: View, Equatable {VStack(alignment: .leading, spacing: 4) {if !label {} else if l.speaker == "me" { Text("你").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.accentInk) }+ else if onAssign != nil, !voices.isEmpty {+ Button { assigning = assigning == l.id ? nil : l.id } label: {+ HStack(spacing: 4) {+ if let n = speakers[l.id] { SpeakerTag(number: n) } else { UnknownSpeakerTag() }+ Image(systemName: "chevron.down").font(.system(size: 8, weight: .bold)).foregroundStyle(Palette.tertiary)+ }+ .padding(.horizontal, assigning == l.id ? 6 : 0).frame(height: 20)+ .background(RoundedRectangle(cornerRadius: 6).fill(assigning == l.id ? Color.white : .clear))+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain).help(ls.count > 1 ? L("这段是谁说的") : L("这句是谁说的"))+ }else if let n = speakers[l.id] { SpeakerTag(number: n) }else if !speakers.isEmpty { UnknownSpeakerTag() }Text(highlighted(l.src, current: isMatch)).font(.system(size: 14)).lineSpacing(2).textSelection(.enabled)@@ -738,6 +753,14 @@ struct TranscriptListView<Partial: View>: View, Equatable {Text(highlighted(d, current: isMatch)).font(.system(size: 13)).foregroundStyle(Palette.secondary).lineSpacing(2).textSelection(.enabled)}+ if assigning == l.id, let onAssign {+ LineSpeakerPicker(voices: voices, current: l.voice.flatMap { voices[$0] != nil ? $0 : nil },+ nearby: nearby(ls), several: ls.count > 1) { v in+ assigning = nil+ onAssign(Set(ls.map(\.id)), v)+ }+ .padding(.top, 6)+ }}Spacer(minLength: 0)}@@ -748,6 +771,52 @@ struct TranscriptListView<Partial: View>: View, Equatable {}+extension TranscriptListView {+ /// The voices speaking just before and after a paragraph, most likely the right one.+ func nearby(_ ls: [TranscriptLine]) -> [Int] {+ guard let i = lines.firstIndex(where: { $0.id == ls[0].id }) else { return [] }+ let j = i + ls.count+ var out: [Int] = []+ for k in [i - 1, j, i - 2, j + 1] where lines.indices.contains(k) {+ if let v = lines[k].voice, voices[v] != nil, !out.contains(v), !ls.contains(where: { $0.voice == v }) { out.append(v) }+ }+ return out+ }+}++/// The notes window's transcript reads as paragraphs: one person's lines within 30 seconds of the+/// paragraph's first are one block, one time, instead of a row and a rule for every fragment.+enum TranscriptParagraphs {+ static let span: Double = 30++ static func group(_ lines: [TranscriptLine], _ speakers: [String: Int]) -> [[TranscriptLine]] {+ var out: [[TranscriptLine]] = []+ var key: String?+ for l in lines {+ let k = l.speaker == "me" ? "me" : speakers[l.id].map { "n\($0)" } ?? "?"+ if k == key, let first = out.last?.first, l.t - first.t <= span {+ out[out.count - 1].append(l)+ } else {+ out.append([l])+ }+ key = k+ }+ return out+ }++ /// Sentences side by side: a space between words, none after Chinese or Japanese.+ static func join(_ parts: [String]) -> String {+ var out = ""+ for p in parts.map({ $0.trimmingCharacters(in: .whitespaces) }) where !p.isEmpty {+ if let last = out.unicodeScalars.last, !(last.properties.isIdeographic || "。!?,、;:”)".unicodeScalars.contains(last)) {+ out += " "+ }+ out += p+ }+ return out+ }+}+enum TranscriptPartial {/// The caption keeps the last sentence after it is finished: only show text not yet a line.static func shows(_ partial: String, live: Bool, after last: String?) -> Bool {diff --git a/Sources/LiveSubs/NotesWindow.swift b/Sources/LiveSubs/NotesWindow.swiftindex b0cd8bf..5dea2f7 100644--- a/Sources/LiveSubs/NotesWindow.swift+++ b/Sources/LiveSubs/NotesWindow.swift@@ -101,6 +101,13 @@ final class NotesWindowController: NSObject, NSWindowDelegate {p.setFrame(f, display: true, animate: true)}+ /// After a name is typed: the keyboard goes back to the meeting app, which never stopped being active.+ func returnKeyboard() {+ guard let panel, panel.isKeyWindow else { return }+ panel.makeFirstResponder(nil)+ if !NSApp.isActive { NSWorkspace.shared.frontmostApplication?.activate() }+ }+func place(_ r: NSRect) { panel?.setFrame(r, display: true) }/// Debug control only: what the close button does.@@ -143,6 +150,8 @@ struct NotesWindowView: View {/// "结束" was clicked during a meeting with lines: the confirmation strip is showing.@State private var confirmEnd = false@State private var languageOpen = false+ /// The voice whose editor is open under the people row.+ @State private var editingVoice: Int?/// When the reader last scrolled the notes: a live update only brings the current topic into/// view when they haven't just been reading something else.@State private var notesScrolledAt = Date.distantPast@@ -179,6 +188,7 @@ struct NotesWindowView: View {}// The title bar is transparent: start the header beside its buttons, not below a blank band..ignoresSafeArea(.container, edges: .top)+ .overlay(alignment: .bottom) { SpeakerUndoToast(model: model, session: session?.id) }}}.frame(width: geo.size.width, height: geo.size.height)@@ -653,7 +663,8 @@ struct NotesWindowView: View {private var notesScroll: some View {ScrollViewReader { proxy inScrollView {- NotesContentView(notes: engine.notes, fresh: engine.fresh, live: live,+ NotesContentView(notes: session.map { SpeakerLabels.named(engine.notes, SpeakerLabels.names($0)) } ?? engine.notes,+ fresh: engine.fresh, live: live,updating: engine.state == .updating,summaryJustChanged: engine.summaryChangedAt.map { now.timeIntervalSince($0) < 20 } ?? false,coveredUntil: lastCovered > 0 ? lastCovered : nil,@@ -689,12 +700,15 @@ struct NotesWindowView: View {let speakers = model.settings.speakerVoices ? SpeakerLabels.numbers(lines) : [:]return VStack(alignment: .leading, spacing: 10) {if !speakers.isEmpty, let s = session {- SpeakerStrip(model: model, session: s) { voice in model.editSpeaker(session: s.id, voice: voice) }+ SpeakerStrip(model: model, session: s, editing: $editingVoice)}TranscriptListView(lines: lines, topics: engine.notes.topics, terms: searchTerms,currentMatch: ms.isEmpty ? nil : ms[currentIndex], live: live,partialShown: TranscriptPartial.shows(model.liveSource, live: live, after: lines.last?.src),- jumpTo: jumpTo, speakers: speakers, startedAt: store.liveStart) {+ jumpTo: jumpTo, speakers: speakers, startedAt: store.liveStart,+ identifying: model.identifyingLanguage,+ voices: speakers.isEmpty ? [:] : SpeakerLabels.voiceNumbers(lines), marked: editingVoice,+ onAssign: { ids, voice in if let s = session { model.assignLines(session: s.id, ids, to: voice) } }) {LivePartialRow(model: model, startedAt: store.liveStart)}.equatable()diff --git a/Sources/LiveSubs/SessionStore.swift b/Sources/LiveSubs/SessionStore.swiftindex 2d26b2e..f3dcd18 100644--- a/Sources/LiveSubs/SessionStore.swift+++ b/Sources/LiveSubs/SessionStore.swift@@ -196,6 +196,41 @@ final class SessionStore: ObservableObject {scheduleSave(id)}+ /// The user says a line (or a paragraph of them) was someone else's: those lines take that voice.+ func setLineVoices(_ id: String, lines ids: Set<String>, _ voice: Int) {+ guard let i = index(id) else { return }+ for j in sessions[i].lines.indices where ids.contains(sessions[i].lines[j].id) && sessions[i].lines[j].speaker == "them" {+ sessions[i].lines[j].voice = voice+ }+ saveNow(id)+ }++ /// Who said what in a meeting, taken before a speaker edit so 撤销 can put it back.+ struct VoiceSnapshot {+ /// Every line's voice then (nil included), by line id.+ let voices: [String: Int?]+ let names: [String: String]?+ let guesses: [String: VoiceGuess]?+ }++ func voiceSnapshot(_ id: String) -> VoiceSnapshot? {+ guard let s = session(id) else { return nil }+ var voices: [String: Int?] = [:]+ for l in s.lines { voices[l.id] = .some(l.voice) }+ return VoiceSnapshot(voices: voices, names: s.voiceNames, guesses: s.voiceGuesses)+ }++ func restore(_ id: String, _ snap: VoiceSnapshot) {+ guard let i = index(id) else { return }+ // Lines heard since keep the voice they were given.+ for j in sessions[i].lines.indices {+ if let v = snap.voices[sessions[i].lines[j].id] { sessions[i].lines[j].voice = v }+ }+ sessions[i].voiceNames = snap.names+ sessions[i].voiceGuesses = snap.guesses+ saveNow(id)+ }+/// The user names a voice. nil drops their name (Ling's guess shows again); "" keeps 说话人 N.func setVoiceName(_ id: String, voice: Int, _ name: String?) {guard let i = index(id) else { return }diff --git a/Sources/LiveSubs/SpeakerID.swift b/Sources/LiveSubs/SpeakerID.swiftindex 56c61dc..2c3c86e 100644--- a/Sources/LiveSubs/SpeakerID.swift+++ b/Sources/LiveSubs/SpeakerID.swift@@ -264,6 +264,25 @@ enum SpeakerLabels {/// "George", else "说话人 2".static func label(_ number: Int, _ names: [Int: String]) -> String { names[number] ?? L("说话人 \(number)") }+ /// The notes as shown: Ling wrote "说话人 6" before anyone named them; show the name since given.+ static func named(_ notes: MeetingNotes, _ names: [Int: String]) -> MeetingNotes {+ guard !names.isEmpty else { return notes }+ func swap(_ text: String) -> String {+ guard text.contains("说话人") || text.contains("Speaker") else { return text }+ var out = text+ for (n, name) in names.sorted(by: { $0.key > $1.key }) { // 说话人 12 before 说话人 1+ for form in ["说话人 \(n)", "说话人\(n)", "Speaker \(n)"] { out = out.replacingOccurrences(of: form, with: name) }+ }+ return out+ }+ var n = notes+ n.summary = swap(n.summary)+ n.topics = n.topics.map { t in var t = t; t.title = swap(t.title); t.summary = swap(t.summary); t.points = t.points.map(swap); return t }+ n.conclusions = n.conclusions.map { var i = $0; i.text = swap(i.text); i.owner = i.owner.map(swap); return i }+ n.todos = n.todos.map { var i = $0; i.text = swap(i.text); i.owner = i.owner.map(swap); return i }+ return n+ }+/// Distinct voices on show, for the people row.static func shownCount(_ lines: [TranscriptLine]) -> Int { Set(numbers(lines).values).count }}@@ -389,10 +408,12 @@ enum SpeakerNameGuess {}}-/// The notes window asking the records window to open the editor for one voice.-struct SpeakerEditRequest: Equatable {+/// A speaker edit that can still be taken back.+struct SpeakerUndo: Identifiable {+ let id = UUID()let session: String- let voice: Int+ let snapshot: SessionStore.VoiceSnapshot+ var text: String}/// Asks Ling for names on its own: once two voices are on show, again every 20 lines, and once more@@ -447,7 +468,7 @@ final class SpeakerNamer: ObservableObject {enum SpeakerColor {private static let inks: [Color] = [Color(red: 0.059, green: 0.482, blue: 0.424), Color(red: 0.478, green: 0.298, blue: 0.761),Color(red: 0.690, green: 0.227, blue: 0.478), Color(red: 0.541, green: 0.353, blue: 0)]- static func ink(_ n: Int) -> Color { inks[(n - 1) % inks.count] }+ static func ink(_ n: Int) -> Color { inks[(max(1, n) - 1) % inks.count] }}/// "说话人 2" above a line.@@ -489,91 +510,126 @@ struct UnknownSpeakerTag: View {struct SpeakerStrip: View {@ObservedObject var model: AppModellet session: Session- /// Set in the notes window: a click hands the voice over instead of editing in place.- var edit: ((Int) -> Void)? = nil- @State private var editing: Int?+ /// The notes window's voice being edited: the editor opens inline instead of as a popover.+ var editing: Binding<Int?>? = nil+ @State private var popover: Int?var body: some View {let numbers = SpeakerLabels.voiceNumbers(session.lines)let names = SpeakerLabels.names(session)- HStack(alignment: .top, spacing: 8) {- FlowLayout(spacing: 6) {- ForEach(numbers.sorted { $0.value < $1.value }, id: \.key) { voice, n in- Button { if let edit { edit(voice) } else { editing = voice } } label: {- HStack(spacing: 5) {- Circle().fill(SpeakerColor.ink(n)).frame(width: 6, height: 6)- Text(SpeakerLabels.label(n, names)).font(.system(size: 11, weight: .semibold)).foregroundStyle(SpeakerColor.ink(n))+ VStack(alignment: .leading, spacing: 10) {+ HStack(alignment: .top, spacing: 8) {+ FlowLayout(spacing: 6) {+ ForEach(numbers.sorted { $0.value < $1.value }, id: \.key) { voice, n in+ let on = (editing?.wrappedValue ?? popover) == voice+ Button {+ if let editing { editing.wrappedValue = on ? nil : voice } else { popover = voice }+ } label: {+ HStack(spacing: 5) {+ Circle().fill(on ? Color.white : SpeakerColor.ink(n)).frame(width: 6, height: 6)+ Text(SpeakerLabels.label(n, names)).font(.system(size: 11, weight: .semibold))+ .foregroundStyle(on ? Color.white : SpeakerColor.ink(n))+ }+ .fixedSize()+ .padding(.horizontal, 8).frame(height: 22)+ .background(Capsule().fill(on ? SpeakerColor.ink(n) : SpeakerColor.ink(n).opacity(0.08)))+ .contentShape(Capsule())+ }+ .buttonStyle(.plain)+ .help(SpeakerLabels.guessed(session)[n].map { _ in L("Ling 从对话里认出,点一下可以改") } ?? L("改名字,或和别人合并"))+ .popover(isPresented: Binding(get: { editing == nil && popover == voice }, set: { if !$0 { popover = nil } }), arrowEdge: .bottom) {+ SpeakerEditor(model: model, namer: model.speakerNamer, sessionID: session.id, voice: voice) { popover = nil }+ }}- .fixedSize()- .padding(.horizontal, 8).frame(height: 22)- .background(Capsule().fill(SpeakerColor.ink(n).opacity(0.08)))- .contentShape(Capsule())}- .buttonStyle(.plain)- .help(SpeakerLabels.guessed(session)[n].map { _ in L("Ling 从对话里认出,点一下可以改") } ?? L("改名字,或和别人合并"))- .popover(isPresented: Binding(get: { editing == voice }, set: { if !$0 { editing = nil } }), arrowEdge: .bottom) {- SpeakerEditor(model: model, namer: model.speakerNamer, sessionID: session.id, voice: voice) { editing = nil }+ Spacer(minLength: 0)+ Button { model.settings.speakerVoices = false } label: {+ Text("不准?关掉").font(.system(size: 11)).foregroundStyle(Palette.secondary).underline().fixedSize()}+ .buttonStyle(.plain)+ .frame(height: 22)+ .help(L("关掉说话人识别,记录里的名字一起收起"))}- ExperimentBadge().frame(height: 22)- }- Spacer(minLength: 0)- Button { model.settings.speakerVoices = false } label: {- Text("不准?关掉").font(.system(size: 11)).foregroundStyle(Palette.secondary).underline().fixedSize()+ if let editing, let voice = editing.wrappedValue, numbers[voice] != nil {+ SpeakerEditor(model: model, namer: model.speakerNamer, sessionID: session.id, voice: voice, inline: true) {+ editing.wrappedValue = nil+ model.notesWindow.returnKeyboard()+ }+ .id(voice)}- .buttonStyle(.plain)- .frame(height: 22)- .help(L("关掉说话人识别,记录里的名字一起收起"))- }- .onAppear {- openRequested()- model.speakerNamer.guess(session.id)}- .onChange(of: model.speakerEdit) { _, _ in openRequested() }- }-- /// The notes window asked to edit a voice of this meeting.- private func openRequested() {- guard edit == nil, let req = model.speakerEdit, req.session == session.id else { return }- model.speakerEdit = nil- DispatchQueue.main.async { editing = req.voice }+ .onAppear { model.speakerNamer.guess(session.id) }}}-/// Correct one voice: its name (Ling's guess is already filled in), or merge it into another voice.+/// Correct one voice: its name (Ling's guess and people from 人名和术语 are a click away), or merge it+/// into another voice. `inline` (the notes window): a click on a name or a merge applies at once.struct SpeakerEditor: View {@ObservedObject var model: AppModel@ObservedObject var namer: SpeakerNamerlet sessionID: Stringlet voice: Int+ var inline = falselet close: () -> Void@State private var draft = ""+ @State private var allMerges = false+ @FocusState private var typing: Boolprivate var session: Session? { model.store.session(sessionID) }var body: some View {- if let s = session {+ // Gone once merged into someone else: the editor closes on the next turn.+ if let s = session, let n = SpeakerLabels.voiceNumbers(s.lines)[voice] {let numbers = SpeakerLabels.voiceNumbers(s.lines)let names = SpeakerLabels.names(s)- let n = numbers[voice] ?? 0let guess = SpeakerLabels.guessed(s)[n]VStack(alignment: .leading, spacing: 12) {HStack(spacing: 6) {Circle().fill(SpeakerColor.ink(n)).frame(width: 8, height: 8)Text(SpeakerLabels.label(n, names)).font(.system(size: 14, weight: .bold))- Spacer()Text("说了 \(s.lines.filter { $0.voice == voice }.count) 句").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ Spacer()+ if inline {+ Button(action: close) {+ Image(systemName: "xmark").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)+ .frame(width: 24, height: 24).contentShape(Rectangle())+ }+ .buttonStyle(.plain).help("收起").accessibilityLabel(L("收起"))+ }}- VStack(alignment: .leading, spacing: 5) {- Text("名字").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)- TextField(L("输入名字"), text: $draft).textFieldStyle(.roundedBorder).onSubmit { save(s, guess) }- if let guess {+ VStack(alignment: .leading, spacing: 6) {+ Text("是谁").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)+ let picks = suggestions(s, names: names, number: n, guess: guess)+ if !picks.isEmpty {+ FlowLayout(spacing: 6) {+ ForEach(picks, id: \.self) { name in+ choice(name, dark: name == names[n]) {+ if inline { apply(s, guess, name) } else { draft = name }+ }+ }+ }+ }+ HStack(spacing: 8) {+ TextField(L("输入名字"), text: $draft).textFieldStyle(.roundedBorder)+ .focused($typing)+ .onSubmit { apply(s, guess, draft) }+ .onExitCommand { close() }+ if inline, typing || draft != (names[n] ?? "") {+ SoftButton(L("保存"), dark: true) { apply(s, guess, draft) }+ }+ }+ if inline && typing {+ // The panel holds the keyboard only while a name is typed; Return or Esc gives it back.+ Text("键盘暂时在这里,会议软件收不到 · 回车保存 · Esc 交还")+ .font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.accentInk)+ .fixedSize(horizontal: false, vertical: true)+ } else if let guess {HStack(alignment: .top, spacing: 8) {Text(guess.evidence.isEmpty ? L("Ling 从对话里认出") : L("Ling 从对话里认出:\(guess.evidence)")).font(.system(size: 11)).foregroundStyle(Palette.tertiary).lineLimit(2)Spacer(minLength: 6)Button(L("不是 TA")) {- model.store.setVoiceName(s.id, voice: voice, "")+ model.renameSpeaker(session: s.id, voice: voice, "")close()}.buttonStyle(.plain).font(.system(size: 11)).foregroundStyle(Palette.secondary)@@ -586,38 +642,131 @@ struct SpeakerEditor: View {if !others.isEmpty {VStack(alignment: .leading, spacing: 6) {Text("其实是同一个人").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)- HStack(spacing: 6) {- ForEach(others, id: \.key) { other, on in- SoftButton(L("并入 \(SpeakerLabels.label(on, names))")) {- model.store.mergeVoice(s.id, voice, into: other)- if s.id == model.store.liveID { model.speakers.merge(voice, into: other) }+ FlowLayout(spacing: 6) {+ ForEach(allMerges ? others : Array(others.prefix(3)), id: \.key) { other, on in+ choice(L("并入 \(SpeakerLabels.label(on, names))")) {+ model.mergeSpeaker(session: s.id, voice, into: other)close()}}+ if others.count > 3 && !allMerges {+ choice(L("更多")) { allMerges = true }+ }}}}- HStack(spacing: 8) {- Spacer()- SoftButton(L("取消")) { close() }- SoftButton(L("完成"), dark: true) { save(s, guess) }+ if !inline {+ HStack(spacing: 8) {+ Spacer()+ SoftButton(L("取消")) { close() }+ SoftButton(L("完成"), dark: true) { apply(s, guess, draft) }+ }+ }+ }+ .padding(inline ? 14 : 16)+ .frame(width: inline ? nil : 320)+ .frame(maxWidth: inline ? .infinity : nil, alignment: .leading)+ .background {+ if inline {+ RoundedRectangle(cornerRadius: 14).fill(Color.white)+ .shadow(color: .black.opacity(0.08), radius: 10, y: 4)+ .overlay(RoundedRectangle(cornerRadius: 14).stroke(Palette.line, lineWidth: 1))}}- .padding(16)- .frame(width: 320).onAppear { draft = names[n] ?? "" }}}+ private func choice(_ title: String, dark: Bool = false, action: @escaping () -> Void) -> some View {+ Button(action: action) {+ Text(title).font(.system(size: 12, weight: .semibold))+ .foregroundStyle(dark ? Color.white : Palette.ink)+ .padding(.horizontal, 10).frame(height: 28)+ .background(RoundedRectangle(cornerRadius: 8).fill(dark ? Palette.ink : Color.white))+ .overlay(RoundedRectangle(cornerRadius: 8).stroke(dark ? Palette.ink : Palette.line, lineWidth: 1))+ .fixedSize()+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ }++ /// Ling's guess first, then people the notes mention, without names other voices already have.+ private func suggestions(_ s: Session, names: [Int: String], number: Int, guess: VoiceGuess?) -> [String] {+ let taken = Set(names.filter { $0.key != number }.values)+ var out: [String] = []+ if let g = s.voiceGuesses?[String(voice)]?.name ?? guess?.name { out.append(g) }+ for t in NoteTerm.people(s.notes?.terms ?? []) where !out.contains(t) && !taken.contains(t) { out.append(t) }+ if let mine = names[number], !out.contains(mine) { out.insert(mine, at: 0) }+ return Array(out.prefix(4))+ }+/// Keeping Ling's name stores nothing, so a later, better guess can still replace it.- private func save(_ s: Session, _ guess: VoiceGuess?) {- let name = draft.trimmingCharacters(in: .whitespacesAndNewlines)- if let guess, name == guess.name { model.store.setVoiceName(s.id, voice: voice, nil) }- else if s.voiceNames?[String(voice)] != nil || !name.isEmpty { model.store.setVoiceName(s.id, voice: voice, name) }+ private func apply(_ s: Session, _ guess: VoiceGuess?, _ typed: String) {+ let name = typed.trimmingCharacters(in: .whitespacesAndNewlines)+ if let guess, name == guess.name { model.renameSpeaker(session: s.id, voice: voice, nil) }+ else if s.voiceNames?[String(voice)] != nil || !name.isEmpty { model.renameSpeaker(session: s.id, voice: voice, name) }close()}}+/// "这句是谁说的": the people on show, the ones speaking just before and after first. Picked → done.+struct LineSpeakerPicker: View {+ /// Voice → speaker number, for the voices on show.+ let voices: [Int: Int]+ let current: Int?+ let nearby: [Int]+ let several: Bool+ let pick: (Int) -> Void+ @Environment(\.speakerNames) private var names++ var body: some View {+ let order = voices.keys.sorted { a, b in+ let ia = nearby.firstIndex(of: a) ?? Int.max, ib = nearby.firstIndex(of: b) ?? Int.max+ return ia != ib ? ia < ib : voices[a]! < voices[b]!+ }+ VStack(alignment: .leading, spacing: 8) {+ Text(several ? "这段是谁说的" : "这句是谁说的").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.secondary)+ FlowLayout(spacing: 6) {+ ForEach(order, id: \.self) { v in+ let n = voices[v]!+ Button { pick(v) } label: {+ HStack(spacing: 5) {+ Circle().fill(SpeakerColor.ink(n)).frame(width: 6, height: 6)+ Text(SpeakerLabels.label(n, names)).font(.system(size: 12, weight: .semibold)).foregroundStyle(SpeakerColor.ink(n))+ }+ .padding(.horizontal, 9).frame(height: 28)+ .background(RoundedRectangle(cornerRadius: 8).fill(Color.white))+ .overlay(RoundedRectangle(cornerRadius: 8).stroke(v == current ? SpeakerColor.ink(n) : Palette.line, lineWidth: 1))+ .fixedSize()+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ }+ }+ }+ }+}++/// "说话人 6 已改成 David · 撤销", for a few seconds after a speaker edit.+struct SpeakerUndoToast: View {+ @ObservedObject var model: AppModel+ let session: String?++ var body: some View {+ if let u = model.speakerUndo, u.session == session, !u.text.isEmpty {+ HStack(spacing: 14) {+ Text(u.text).font(.system(size: 13)).foregroundStyle(.white).lineLimit(2)+ Button("撤销") { model.undoSpeakerEdit() }+ .buttonStyle(.plain).font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.accentPale)+ }+ .padding(.horizontal, 14).frame(minHeight: 38)+ .background(RoundedRectangle(cornerRadius: 10).fill(Palette.ink).shadow(color: .black.opacity(0.2), radius: 12, y: 6))+ .padding(.bottom, 18)+ .transition(.opacity)+ }+ }+}+/// Debug render (`speakersRender`): the people row and the first lines, labelled as the transcript/// labels them (a name only where the speaker changes).struct SpeakerPreview: View {diff --git a/Sources/LiveSubs/Views.swift b/Sources/LiveSubs/Views.swiftindex ab7e5ea..41f4dc3 100644--- a/Sources/LiveSubs/Views.swift+++ b/Sources/LiveSubs/Views.swift@@ -725,6 +725,7 @@ struct MainWindowView: View {detail.frame(maxWidth: .infinity, maxHeight: .infinity).onGeometryChange(for: CGFloat.self) { $0.size.width } action: { detailWidth = $0 }+ .overlay(alignment: .bottom) { SpeakerUndoToast(model: model, session: selection) }}.background(Color.white.ignoresSafeArea()).background(Button("") { searchFocused = true }.keyboardShortcut("f").opacity(0))@@ -1206,8 +1207,11 @@ struct MainWindowView: View {let speakers = settings.speakerVoices ? SpeakerLabels.numbers(s.lines) : [:]if !speakers.isEmpty { SpeakerStrip(model: model, session: s).padding(.bottom, 8) }let starts = SpeakerLabels.runStarts(s.lines, speakers)+ let voices = SpeakerLabels.voiceNumbers(s.lines)ForEach(s.lines) { l in- lineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || starts.contains(l.id), voices: !speakers.isEmpty).id(l.id)+ lineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || starts.contains(l.id), voices: !speakers.isEmpty, in: s)+ .contextMenu { if !speakers.isEmpty, l.speaker == "them" { assignMenu(s, l, voices) } }+ .id(l.id)}}.environment(\.speakerNames, SpeakerLabels.names(s))@@ -1245,9 +1249,16 @@ struct MainWindowView: View {}VStack(alignment: .leading, spacing: 5) {if !label {+ } else if voices, !me, let s = shownSession {+ // A click on whose line it is: say it was someone else's.+ Menu { assignMenu(s, l, SpeakerLabels.voiceNumbers(s.lines)) } label: {+ if let speaker { SpeakerTag(number: speaker) } else { UnknownSpeakerTag() }+ }+ .menuStyle(.borderlessButton).menuIndicator(.visible).fixedSize()+ .help(L("这句是谁说的"))} else if let speaker { SpeakerTag(number: speaker) }- else if voices, !me { UnknownSpeakerTag() }- else {+ else if shownSession?.sourceFile == nil {+ // An imported file has no "other side": its lines carry no label.Text(me ? L("你") : L("对方")).font(.system(size: 11, weight: .semibold)).foregroundStyle(me ? Palette.accentInk : Palette.secondary)}@@ -1272,6 +1283,21 @@ struct MainWindowView: View {}+extension MainWindowView {+ /// "这句是谁说的": the people on show; the line takes that voice.+ @ViewBuilder+ func assignMenu(_ s: Session, _ l: TranscriptLine, _ voices: [Int: Int]) -> some View {+ let names = SpeakerLabels.names(s)+ Section("这句是谁说的") {+ ForEach(voices.sorted { $0.value < $1.value }, id: \.key) { v, n in+ Button(SpeakerLabels.label(n, names) + (l.voice == v ? " ✓" : "")) {+ model.assignLines(session: s.id, [l.id], to: v)+ }+ }+ }+ }+}+/// A meeting's notes in the main window: the same notes view as the live window, or a way to/// make them for a meeting recorded without a key.struct SessionNotesView: View {@@ -1292,7 +1318,7 @@ struct SessionNotesView: View {VStack(alignment: .leading, spacing: 40) {headerif let notes, !notes.isEmpty {- NotesContentView(notes: notes, fresh: live ? engine.fresh : [], live: live, document: true,+ NotesContentView(notes: SpeakerLabels.named(notes, SpeakerLabels.names(session)), fresh: live ? engine.fresh : [], live: live, document: true,endedAt: session.lines.last?.t, onJump: onJump)} else if generating || (live && ling.hasKey && !session.lines.isEmpty) {NotesGeneratingView(heard: session.lines.count)