知了 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: fix a misheard word yourself from the meeting record, settle waiting fixes after the meeting, and undo any fix
wqugurub6f1f8ccd92e
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.stringsindex e725132..8c9d3c5 100644--- a/Resources/en.lproj/Localizable.strings+++ b/Resources/en.lproj/Localizable.strings@@ -1259,7 +1259,6 @@"听成" = "Heard as";"改回" = "Revert";"这样改对吗?" = "Is this fix right?";-"确认后整场一起改,以后也照此改" = "Fixes the whole meeting, and future ones";"对" = "Yes";"不对" = "No";@@ -1277,12 +1276,11 @@"粘贴导入…" = "Paste to import…";"会中确认" = "Confirmed";"你加的" = "Added by you";-"改过 %lld 次" = "Fixed %lld times";+"改过 %lld 次" = "Fixed ×%lld";"还没用上" = "Not used yet";"从词表里删掉" = "Remove from the list";"粘贴导入" = "Paste to import";"一行一个。常被听错的词,写在 = 后面" = "One per line. Put common mishearings after =";-"新增 %lld · 更新 %lld · 跳过 %lld" = "%lld added · %lld updated · %lld skipped";"第 %@ 行没加进去:超过 40 个字" = "Line %@ not added: over 40 characters";/* AISettings: 改正听错的词 */@@ -1290,3 +1288,35 @@"已关" = "Off";"随翻译一起发,几乎不多花" = "Sent with the translation, barely any extra cost";"在“词表”里打开" = "Turn on in Word list";++/* 改正听错的词: 改这句…, 撤销, 词表 */+"改这句" = "Edit line";+"记进词表,以后自动改" = "Save to Word list for next time";+"整场听成 %@ 的 %lld 处都改" = "All %2$lld places heard as %1$@ in this meeting";+"只改这一处" = "Just this one";+"回车 改成 · esc 取消" = "Return to apply · Esc to cancel";+"改成" = "Apply";+"改了 %lld 处听错的词" = "Fixed %lld misheard words";+"改成…" = "Change to…";+"改了 %lld 处听错的词,%lld 处等你确认" = "Fixed %lld misheard words · %lld to confirm";+"已收进人名和术语,稍后再看" = "Saved to Names and terms for later";+"已改 %@ → %@,记进词表" = "%@ → %@ · Saved to Word list";+"这场不再问 %@" = "Won't ask about %@ again in this meeting";+"已改回 %@,这场不再改" = "Reverted to %@ for this meeting";+"已改 %lld 处:%@ → %@,记进词表" = "Changed %lld: %@ → %@ · Saved to Word list";+"已改 %lld 处:%@ → %@" = "Changed %lld: %@ → %@";+"确认后整场一起改,以后也这样改" = "Applies to this meeting and future ones";+"稍后再看" = "Decide later";+"等你确认,还没改" = "Waiting for you, not changed yet";+"听成 %@ · 改了 %lld 处" = "Heard as %@ · %lld fixed";+"听成 %@" = "Heard as %@";+"改这句…" = "Edit line…";+"已删除" = "Deleted";+"点一下改写法" = "Click to change the spelling";+"加一个容易听错的词" = "Add misheard form";+"“%@”已经记在 %@ 下" = "“%@” already belongs to %@";+"改给 %@" = "Move to %@";+"两个都留" = "Keep both";+"删掉这个听错的词" = "Remove this misheard form";+"新增 %lld · 补充听成 %lld · 跳过 %lld" = "%lld new · %lld updated · %lld skipped";+"导入 %lld 个" = "Import %lld";diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.stringsindex 61e5de5..440e341 100644--- a/Resources/ja.lproj/Localizable.strings+++ b/Resources/ja.lproj/Localizable.strings@@ -1259,7 +1259,6 @@"听成" = "認識";"改回" = "元に戻す";"这样改对吗?" = "この修正で合っていますか?";-"确认后整场一起改,以后也照此改" = "会議全体に反映し、次回からも同じく直します";"对" = "はい";"不对" = "いいえ";@@ -1282,7 +1281,6 @@"从词表里删掉" = "リストから削除";"粘贴导入" = "貼り付けて追加";"一行一个。常被听错的词,写在 = 后面" = "1 行に 1 つ。よくある聞き間違いは = の後に";-"新增 %lld · 更新 %lld · 跳过 %lld" = "追加 %lld · 更新 %lld · スキップ %lld";"第 %@ 行没加进去:超过 40 个字" = "%@ 行目は追加されませんでした:40 文字を超えています";/* AISettings: 改正听错的词 */@@ -1290,3 +1288,35 @@"已关" = "オフ";"随翻译一起发,几乎不多花" = "翻訳と一緒に送るので、追加費用はほぼなし";"在“词表”里打开" = "「単語リスト」でオン";++/* 改正听错的词: 改这句…, 撤销, 词表 */+"改这句" = "この行を修正";+"记进词表,以后自动改" = "単語リストに保存して次回から自動で修正";+"整场听成 %@ 的 %lld 处都改" = "この会議で %1$@ と聞こえた %2$lld か所すべて";+"只改这一处" = "ここだけ";+"回车 改成 · esc 取消" = "Return で修正 · Esc でキャンセル";+"改成" = "修正";+"改了 %lld 处听错的词" = "聞き間違いを %lld か所修正";+"改成…" = "修正…";+"改了 %lld 处听错的词,%lld 处等你确认" = "聞き間違いを %lld か所修正 · %lld か所が確認待ち";+"已收进人名和术语,稍后再看" = "人名と用語に入れました。あとで確認";+"已改 %@ → %@,记进词表" = "%@ → %@ に修正し、単語リストに保存";+"这场不再问 %@" = "この会議では %@ をもう聞きません";+"已改回 %@,这场不再改" = "%@ に戻しました。この会議では直しません";+"已改 %lld 处:%@ → %@,记进词表" = "%lld か所修正:%@ → %@、単語リストに保存";+"已改 %lld 处:%@ → %@" = "%lld か所修正:%@ → %@";+"确认后整场一起改,以后也这样改" = "この会議全体に反映し、次回からも同じく直します";+"稍后再看" = "あとで";+"等你确认,还没改" = "確認待ち、まだ直していません";+"听成 %@ · 改了 %lld 处" = "%@ と認識 · %lld か所修正";+"听成 %@" = "%@ と認識";+"改这句…" = "この行を修正…";+"已删除" = "削除しました";+"点一下改写法" = "クリックして表記を変更";+"加一个容易听错的词" = "聞き間違いを追加";+"“%@”已经记在 %@ 下" = "「%@」はすでに %@ に入っています";+"改给 %@" = "%@ に移す";+"两个都留" = "両方残す";+"删掉这个听错的词" = "この聞き間違いを削除";+"新增 %lld · 补充听成 %lld · 跳过 %lld" = "追加 %lld · 更新 %lld · スキップ %lld";+"导入 %lld 个" = "%lld 個を追加";diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.stringsindex 8f1ce88..1430081 100644--- a/Resources/ko.lproj/Localizable.strings+++ b/Resources/ko.lproj/Localizable.strings@@ -1259,7 +1259,6 @@"听成" = "인식";"改回" = "되돌리기";"这样改对吗?" = "이렇게 고치는 게 맞나요?";-"确认后整场一起改,以后也照此改" = "회의 전체에 적용하고 다음부터도 이렇게 고칩니다";"对" = "네";"不对" = "아니요";@@ -1282,7 +1281,6 @@"从词表里删掉" = "목록에서 삭제";"粘贴导入" = "붙여 넣어 추가";"一行一个。常被听错的词,写在 = 后面" = "한 줄에 하나. 자주 잘못 듣는 형태는 = 뒤에";-"新增 %lld · 更新 %lld · 跳过 %lld" = "추가 %lld · 업데이트 %lld · 건너뜀 %lld";"第 %@ 行没加进去:超过 40 个字" = "%@번째 줄은 추가되지 않았습니다: 40자 초과";/* AISettings: 改正听错的词 */@@ -1290,3 +1288,35 @@"已关" = "꺼짐";"随翻译一起发,几乎不多花" = "번역과 함께 보내 추가 비용이 거의 없음";"在“词表”里打开" = "‘단어 목록’에서 켜기";++/* 改正听错的词: 改这句…, 撤销, 词表 */+"改这句" = "이 줄 고치기";+"记进词表,以后自动改" = "단어 목록에 저장해 다음부터 자동으로 고치기";+"整场听成 %@ 的 %lld 处都改" = "이 회의에서 %1$@(으)로 들린 %2$lld곳 모두";+"只改这一处" = "여기만";+"回车 改成 · esc 取消" = "Return 적용 · Esc 취소";+"改成" = "적용";+"改了 %lld 处听错的词" = "잘못 들은 단어 %lld곳 고침";+"改成…" = "고치기…";+"改了 %lld 处听错的词,%lld 处等你确认" = "잘못 들은 단어 %lld곳 고침 · %lld곳 확인 필요";+"已收进人名和术语,稍后再看" = "인명과 용어에 넣었습니다. 나중에 확인";+"已改 %@ → %@,记进词表" = "%@ → %@ 고치고 단어 목록에 저장";+"这场不再问 %@" = "이 회의에서는 %@을(를) 다시 묻지 않습니다";+"已改回 %@,这场不再改" = "%@(으)로 되돌렸습니다. 이 회의에서는 고치지 않습니다";+"已改 %lld 处:%@ → %@,记进词表" = "%lld곳 고침: %@ → %@ · 단어 목록에 저장";+"已改 %lld 处:%@ → %@" = "%lld곳 고침: %@ → %@";+"确认后整场一起改,以后也这样改" = "회의 전체에 적용하고 다음부터도 이렇게 고칩니다";+"稍后再看" = "나중에";+"等你确认,还没改" = "확인 대기 중, 아직 안 고침";+"听成 %@ · 改了 %lld 处" = "%@(으)로 들림 · %lld곳 고침";+"听成 %@" = "%@(으)로 들림";+"改这句…" = "이 줄 고치기…";+"已删除" = "삭제함";+"点一下改写法" = "클릭해 표기 바꾸기";+"加一个容易听错的词" = "잘못 듣는 형태 추가";+"“%@”已经记在 %@ 下" = "‘%@’은(는) 이미 %@에 있습니다";+"改给 %@" = "%@(으)로 옮기기";+"两个都留" = "둘 다 유지";+"删掉这个听错的词" = "이 형태 삭제";+"新增 %lld · 补充听成 %lld · 跳过 %lld" = "추가 %lld · 업데이트 %lld · 건너뜀 %lld";+"导入 %lld 个" = "%lld개 가져오기";diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.stringsindex 8acdaa2..56e45dd 100644--- a/Resources/zh-Hans.lproj/Localizable.strings+++ b/Resources/zh-Hans.lproj/Localizable.strings@@ -1259,7 +1259,6 @@"听成" = "听成";"改回" = "改回";"这样改对吗?" = "这样改对吗?";-"确认后整场一起改,以后也照此改" = "确认后整场一起改,以后也照此改";"对" = "对";"不对" = "不对";@@ -1282,7 +1281,6 @@"从词表里删掉" = "从词表里删掉";"粘贴导入" = "粘贴导入";"一行一个。常被听错的词,写在 = 后面" = "一行一个。常被听错的词,写在 = 后面";-"新增 %lld · 更新 %lld · 跳过 %lld" = "新增 %lld · 更新 %lld · 跳过 %lld";"第 %@ 行没加进去:超过 40 个字" = "第 %@ 行没加进去:超过 40 个字";/* AISettings: 改正听错的词 */@@ -1290,3 +1288,35 @@"已关" = "已关";"随翻译一起发,几乎不多花" = "随翻译一起发,几乎不多花";"在“词表”里打开" = "在“词表”里打开";++/* 改正听错的词: 改这句…, 撤销, 词表 */+"改这句" = "改这句";+"记进词表,以后自动改" = "记进词表,以后自动改";+"整场听成 %@ 的 %lld 处都改" = "整场听成 %@ 的 %lld 处都改";+"只改这一处" = "只改这一处";+"回车 改成 · esc 取消" = "回车 改成 · esc 取消";+"改成" = "改成";+"改了 %lld 处听错的词" = "改了 %lld 处听错的词";+"改成…" = "改成…";+"改了 %lld 处听错的词,%lld 处等你确认" = "改了 %lld 处听错的词,%lld 处等你确认";+"已收进人名和术语,稍后再看" = "已收进人名和术语,稍后再看";+"已改 %@ → %@,记进词表" = "已改 %@ → %@,记进词表";+"这场不再问 %@" = "这场不再问 %@";+"已改回 %@,这场不再改" = "已改回 %@,这场不再改";+"已改 %lld 处:%@ → %@,记进词表" = "已改 %lld 处:%@ → %@,记进词表";+"已改 %lld 处:%@ → %@" = "已改 %lld 处:%@ → %@";+"确认后整场一起改,以后也这样改" = "确认后整场一起改,以后也这样改";+"稍后再看" = "稍后再看";+"等你确认,还没改" = "等你确认,还没改";+"听成 %@ · 改了 %lld 处" = "听成 %@ · 改了 %lld 处";+"听成 %@" = "听成 %@";+"改这句…" = "改这句…";+"已删除" = "已删除";+"点一下改写法" = "点一下改写法";+"加一个容易听错的词" = "加一个容易听错的词";+"“%@”已经记在 %@ 下" = "“%@”已经记在 %@ 下";+"改给 %@" = "改给 %@";+"两个都留" = "两个都留";+"删掉这个听错的词" = "删掉这个听错的词";+"新增 %lld · 补充听成 %lld · 跳过 %lld" = "新增 %lld · 补充听成 %lld · 跳过 %lld";+"导入 %lld 个" = "导入 %lld 个";diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex b45466c..921415a 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -1479,6 +1479,7 @@ final class AppModel: ObservableObject {let whole = parts.dropFirst().reduce(parts[0]) { HeardText.join($0, $1) }guard let rec = store.session(entry.session)?.lines.first(where: { $0.id == line }), whole != rec.src else { return }store.setSource(in: entry.session, lineID: line, whole)+ fixes.applyKnown(lineID: line, in: entry.session)refinedLines.insert(line)contentLog("REFINE \(line): \(rec.src) => \(whole)")guard rec.dst != nil else { return }@@ -1556,6 +1557,7 @@ final class AppModel: ObservableObject {joined.cut = seg.cutlastHeard = (joined, prev.line)store.setSource(lineID: prev.line, text)+ if let id = store.liveID { fixes.applyKnown(lineID: prev.line, in: id) }trackRefining(seg, line: prev.line)listen.join(seg.id, into: prev.seg.id, text: text)contentLog("JOIN \(prev.line) += \(seg.text)")@@ -1571,6 +1573,7 @@ final class AppModel: ObservableObject {// 会议室 alone too: a meeting switched to it from 电脑和会议室// would otherwise mark its later room lines 线上.via: seg.id >= ListenEngine.roomIDs || settings.listensToRoom ? "room" : nil))+ if let live = store.liveID { fixes.applyKnown(lineID: id, in: live) }trackRefining(seg, line: id)var kept = segkept.voiceSamples = nil@@ -1803,7 +1806,34 @@ final class AppModel: ObservableObject {case "fixAnswer": // fixAnswer:yes|no[,<id>]let parts = arg.split(separator: ",", maxSplits: 1).map(String.init)let id = parts.count > 1 ? parts[1] : store.liveID ?? store.sessions.first?.id ?? ""- if let first = fixes.pending(in: id).first { fixes.answer(first.fix, yes: parts.first == "yes", in: id) }+ if let first = fixes.asking(in: id) ?? fixes.pending(in: id).first.map({ ($0.line, $0.fix, 1, 1) }) {+ fixes.answer(first.fix, yes: parts.first == "yes", in: id)+ }+ // The recheck without audio: line `<id>` settles as `<text>` and is translated (and fixed) again,+ // with the lines after it in view, as the record's own recognizer would have it.+ case "resettle": // resettle:<line id>=<text>+ let p = arg.split(separator: "=", maxSplits: 1).map(String.init)+ guard p.count == 2, let id = store.liveID, let rec = store.session(id)?.lines.first(where: { $0.id == p[0] }) else { break }+ store.setSource(in: id, lineID: rec.id, p[1])+ fixes.applyKnown(lineID: rec.id, in: id)+ Task { [weak self] in+ guard let self, let out = await self.listen.translate(p[1], source: rec.srcLang, target: rec.dstLang) else { return }+ self.store.setTranslation(in: id, lineID: rec.id, out)+ }+ case "fixLater":+ let id = arg.isEmpty ? store.liveID ?? "" : arg+ if let a = fixes.asking(in: id) { fixes.later(a.fix, in: id) }+ case "fixUndo": fixes.undo()+ case "fixEdit": // fixEdit:<line id>=<new text>[|one|keep0][,<session id>]+ let (head, sid) = { () -> (String, String) in+ if let c = arg.lastIndex(of: ","), !arg[arg.index(after: c)...].contains("=") { return (String(arg[..<c]), String(arg[arg.index(after: c)...])) }+ return (arg, store.liveID ?? store.sessions.first?.id ?? "")+ }()+ let p = head.split(separator: "=", maxSplits: 1).map(String.init)+ guard p.count == 2 else { break }+ let opts = p[1].split(separator: "|").map(String.init)+ let n = fixes.edit(lineID: p[0], in: sid, to: opts[0], everywhere: !opts.contains("one"), remember: !opts.contains("keep0"))+ debugLog("fix edit changed \(n) lines")case "fixRevert": // fixRevert:<line id>[,<session id>]: the line's first applied fixlet parts = arg.split(separator: ",", maxSplits: 1).map(String.init)let id = parts.count > 1 ? parts[1] : store.liveID ?? store.sessions.first?.id ?? ""@@ -1974,8 +2004,10 @@ final class AppModel: ObservableObject {}case "notesRender":// The whole notes column as a PNG, for checking what is below the fold.+ let shownID = notes.shownID ?? store.liveID+ let fixTerms = shownID.flatMap { store.session($0) }.map { AnyView(FixTermsView(fixes: fixes, session: $0) { _ in }) }let view = NotesContentView(notes: notes.notes, fresh: notes.fresh, live: store.liveID != nil,- updating: notes.state == .updating)+ updating: notes.state == .updating, fixTerms: fixTerms).padding(24).frame(width: 460).background(Color.white)let r = ImageRenderer(content: view)r.scale = 2diff --git a/Sources/Cicada/Correction.swift b/Sources/Cicada/Correction.swiftindex 7afd86a..c5b6a15 100644--- a/Sources/Cicada/Correction.swift+++ b/Sources/Cicada/Correction.swift@@ -11,6 +11,8 @@ struct LineFix: Codable, Equatable, Hashable {var ask: Bool? = nil/// The user said no (改回 or 不对): kept so the same line isn't fixed that way again.var off: Bool? = nil+ /// The user's own: said 对, or wrote it (改这句…). A later pass never drops or overrides it.+ var user: Bool? = nilvar applied: Bool { ask != true && off != true }}@@ -132,7 +134,9 @@ enum Correction {static func apply(_ fixes: [LineFix], to src: String) -> (text: String, marks: [Range<String.Index>]) {var text = srcvar spans: [(String, Int)] = [] // replacement and its character offset, kept valid as text changes- for f in fixes where f.applied && !f.from.isEmpty {+ // The user's own last: written against the line as it was shown, other fixes in.+ let ordered = fixes.filter { $0.user != true } + fixes.filter { $0.user == true }+ for f in ordered where f.applied && !f.from.isEmpty {guard let r = text.range(of: f.from) else { continue }let start = text.distance(from: text.startIndex, to: r.lowerBound)let delta = f.to.count - f.from.count@@ -169,12 +173,32 @@ enum Correction {return (translation.trimmingCharacters(in: .whitespacesAndNewlines), edits)}- /// What the lines' fixes become after the service answered for this text again (a joined or- /// refined line): its new fixes, plus every one the user already turned down.+ /// What a line's fixes become after the service answered for it again (a joined line, or the+ /// recheck once the record's recognizer settled it, with the lines after it in view): the+ /// user's decisions stay (said no, said yes, wrote it), and of the rest only what is proposed+ /// again. So a recheck that no longer proposes a fix takes it back.static func merge(_ old: [LineFix], _ new: [LineFix]) -> [LineFix] {- let refused = old.filter { $0.off == true }- let fresh = new.filter { n in !refused.contains { $0.from == n.from && $0.to == n.to } }- return refused + fresh+ let kept = old.filter { $0.off == true || $0.user == true }+ let fresh = new.filter { n in+ let c = core(n.from, n.to)+ return !kept.contains { $0.from == n.from || core($0.from, $0.to).from == c.from }+ }+ return kept + fresh+ }++ /// 改这句…: the user rewrote the line as shown. What changed, as a fix on top of the others,+ /// and the heard form it replaces (for the word list): the words in `src` when they are+ /// there, else the heard words of the fix the user corrected again ("莫纳" → "Morpho" → "Monad").+ static func userEdit(shown: String, edited: String, src: String, fixes: [LineFix]) -> (fix: LineFix, heard: String)? {+ let new = edited.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !new.isEmpty, new != shown else { return nil }+ let c = core(shown, new)+ guard !c.from.isEmpty, !c.to.isEmpty else { return nil }+ var heard = c.from+ if !src.contains(c.from), let earlier = fixes.first(where: { $0.applied && c.from.contains($0.to) }) {+ heard = core(earlier.from, earlier.to).from+ }+ return (LineFix(from: c.from, to: c.to, user: true), heard)}}diff --git a/Sources/Cicada/FixViews.swift b/Sources/Cicada/FixViews.swiftnew file mode 100644index 0000000..85aef55--- /dev/null+++ b/Sources/Cicada/FixViews.swift@@ -0,0 +1,124 @@+import SwiftUI++/// 改这句… in the meeting record: the line as shown, to rewrite. What changed becomes the user's+/// own fix (`LiveFixes.edit`), on every line heard the same way or only this one.+struct LineEditor: View {+ let line: TranscriptLine+ let session: String+ @ObservedObject var fixes: LiveFixes+ let start: String+ let onDone: () -> Void+ @State private var text = ""+ @State private var everywhere = true+ @State private var keep = true+ @FocusState private var focused: Bool++ var body: some View {+ let same = fixes.sameHeard(lineID: line.id, in: session, edited: text)+ VStack(alignment: .leading, spacing: 8) {+ TextField(L("改这句"), text: $text, axis: .vertical)+ .textFieldStyle(.plain).font(.system(size: 15)).lineSpacing(2)+ .padding(.horizontal, 10).padding(.vertical, 7)+ .background(RoundedRectangle(cornerRadius: 8).fill(Color.white))+ .overlay(RoundedRectangle(cornerRadius: 8).stroke(Palette.ink, lineWidth: 1))+ .focused($focused)+ .onSubmit(apply)+ .onExitCommand(perform: onDone)+ if let same {+ HStack(spacing: 6) {+ Text("听成").foregroundStyle(Palette.tertiary)+ Text(same.heard)+ }+ .font(.system(size: 12))+ if same.count > 1 {+ Picker("", selection: $everywhere) {+ Text("整场听成 \(same.heard) 的 \(same.count) 处都改").tag(true)+ Text("只改这一处").tag(false)+ }+ .pickerStyle(.radioGroup).labelsHidden().font(.system(size: 12))+ }+ Toggle("记进词表,以后自动改", isOn: $keep)+ .toggleStyle(.checkbox).font(.system(size: 12))+ .disabled(same.count > 1 && !everywhere)+ }+ HStack(spacing: 8) {+ Text("回车 改成 · esc 取消").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ Spacer()+ SoftButton(L("取消"), action: onDone)+ SoftButton(L("改成"), dark: true, action: apply)+ }+ }+ .padding(.vertical, 2)+ .onAppear { text = start; focused = true }+ }++ private func apply() {+ guard let same = fixes.sameHeard(lineID: line.id, in: session, edited: text) else { onDone(); return }+ let all = same.count > 1 ? everywhere : true+ fixes.edit(lineID: line.id, in: session, to: text, everywhere: all, remember: keep && all)+ onDone()+ }+}++/// Above a finished meeting's transcript: how many words were fixed, and the ones waiting for the+/// user, one at a time (对 / 不对 / 改成…). Nothing once there was nothing to fix.+struct FixReviewBanner: View {+ @ObservedObject var fixes: LiveFixes+ let session: Session+ let onShow: (String) -> Void+ let onEdit: (TranscriptLine, String) -> Void++ var body: some View {+ let waiting = fixes.pending(in: session.id)+ let fixedCount = session.lines.reduce(0) { $0 + ($1.fixes ?? []).filter(\.applied).count }+ if let first = waiting.first {+ let c = Correction.core(first.fix.from, first.fix.to)+ HStack(spacing: 10) {+ Button { onShow(first.line.id) } label: {+ VStack(alignment: .leading, spacing: 2) {+ Text("改了 \(fixedCount) 处听错的词,\(waiting.count) 处等你确认").font(.system(size: 13, weight: .medium))+ .foregroundStyle(Palette.ink)+ (Text("\(c.from) → \(c.to)?") + Text(" · \(TranscriptExport.clock(first.line.t))").foregroundStyle(Palette.tertiary))+ .font(.system(size: 12)).foregroundStyle(Palette.secondary)+ }+ .frame(maxWidth: .infinity, alignment: .leading).contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ SoftButton(L("对"), dark: true) { fixes.answer(first.fix, yes: true, in: session.id) }+ SoftButton(L("不对"), onGrey: true) { fixes.answer(first.fix, yes: false, in: session.id) }+ SoftButton(L("改成…"), onGrey: true) {+ onEdit(first.line, Correction.apply((first.line.fixes ?? []).filter { $0.applied }, to: first.line.src).text)+ }+ }+ .padding(.horizontal, 14).padding(.vertical, 10)+ .background(RoundedRectangle(cornerRadius: 12).fill(Palette.accentWash))+ .overlay(RoundedRectangle(cornerRadius: 12).stroke(Palette.accentPale, lineWidth: 1))+ .onAppear { onShow(first.line.id) }+ } else if fixedCount > 0 {+ Text("改了 \(fixedCount) 处听错的词").font(.system(size: 12)).foregroundStyle(Palette.tertiary)+ }+ }+}++/// The last fix decision said back for a few seconds, with 撤销.+struct FixToast: View {+ @ObservedObject var fixes: LiveFixes++ var body: some View {+ if let t = fixes.toast {+ HStack(spacing: 14) {+ Text(t.text).font(.system(size: 13)).foregroundStyle(.white).lineLimit(1)+ if fixes.canUndo {+ Button(L("撤销")) { fixes.undo() }+ .buttonStyle(.plain).font(.system(size: 13, weight: .semibold))+ .foregroundStyle(Color(red: 1, green: 0.71, blue: 0.61))+ }+ }+ .padding(.horizontal, 14).padding(.vertical, 9)+ .background(RoundedRectangle(cornerRadius: 10).fill(Palette.ink))+ .shadow(color: .black.opacity(0.25), radius: 10, y: 4)+ .transition(.opacity)+ .id(t.id)+ }+ }+}diff --git a/Sources/Cicada/LiveFixes.swift b/Sources/Cicada/LiveFixes.swiftindex 40cca0e..e9d4885 100644--- a/Sources/Cicada/LiveFixes.swift+++ b/Sources/Cicada/LiveFixes.swift@@ -1,10 +1,11 @@import Foundation/// 改正听错的词, between the translation chain and the records: which fixes a line takes, which wait-/// for the user (待确认), and what the user's answers teach the word list. UI-free; the app shows-/// `pending` and passes taps back.+/// for the user (待确认), and what the user's answers and edits teach the word list. Who wins: the+/// user's own decisions, then the word list, then the recheck, then the first live guess. UI-free;+/// the app shows `pending`, `toast` and passes taps back.@MainActor-final class LiveFixes {+final class LiveFixes: ObservableObject {let store: SessionStorelet vocabulary: Vocabularylet settings: AppSettings@@ -12,10 +13,23 @@ final class LiveFixes {var onLineFixed: ((_ session: String, _ line: TranscriptLine) -> Void)?var onChange: (() -> Void)?+ /// The last thing the user did, said back with 撤销 for a few seconds.+ struct Toast: Equatable { let id = UUID(); let text: String }+ @Published private(set) var toast: Toast?+/// Fixes said no to in this meeting ("from→to"), and how often each heard form was turned down/// overall this run: twice and it leaves the word list.private var refused: Set<String> = []private var refusals: [String: Int] = [:]+ /// 稍后再看 on the card: still waiting, but asked again only after the meeting.+ private var deferred: Set<String> = []+ /// What 撤销 puts back: the lines' fixes and the word list as they were.+ private struct Step { let session: String; let lines: [String: [LineFix]]; let words: [Vocabulary.Term]; let refused: Set<String>; let deferred: Set<String> }+ private var undoStack: [Step] = []+ private var toastTimer: Timer?++ /// The card asks about at most this many names in a row; the rest wait for after the meeting.+ static let askAtOnce = 3init(store: SessionStore, vocabulary: Vocabulary, settings: AppSettings) {self.store = store@@ -23,25 +37,31 @@ final class LiveFixes {self.settings = settings}- func meetingStarted() { refused = [] }+ func meetingStarted() { refused = []; deferred = []; undoStack = [] }private static func pair(_ a: String, _ b: String) -> String { a + "\u{1F}" + b }- /// What a finished sentence's request carries; nil while fixing is off.+ // MARK: The service's proposals++ /// What a finished sentence's request carries; nil while fixing is off. On a second pass (a+ /// joined line, or the recheck after the record's recognizer settled it) the lines after it+ /// and the notes' summary are there too.func context(for text: String) -> TranslationService.FixContext? {guard settings.fixMisheard else { return nil }- var topic: String?- var recent: [String] = []+ var ctx = TranslationService.FixContext(topic: nil, words: vocabulary.promptLines(), recent: [])if let (id, line) = store.lineHeard(as: text), let s = store.session(id) {- topic = s.notes?.title ?? (s.renamed == true ? s.title : nil)+ ctx.topic = s.notes?.title ?? (s.renamed == true ? s.title : nil)+ ctx.summary = s.notes?.summaryif let i = s.lines.firstIndex(where: { $0.id == line.id }) {- recent = s.lines[max(0, i - 3)..<i].map(\.shown)+ ctx.recent = s.lines[max(0, i - 3)..<i].map(\.shown)+ ctx.following = s.lines[(i + 1)..<min(s.lines.count, i + 4)].map(\.shown)}}- return .init(topic: topic, words: vocabulary.promptLines(), recent: recent)+ return ctx}- /// The service's proposals for a line heard as `text`.+ /// The service's proposals for a line heard as `text` (none at all is an answer too: on a+ /// recheck it takes back what isn't proposed again).func received(_ text: String, _ edits: [Correction.Edit]) {guard settings.fixMisheard, let (id, line) = store.lineHeard(as: text) else { return }var fresh: [LineFix] = []@@ -60,13 +80,42 @@ final class LiveFixes {default: break}}- let fixes = Correction.merge(line.fixes ?? [], fresh)- guard fixes != line.fixes ?? [] else { return }- store.setFixes(in: id, lineID: line.id, fixes)- if let now = store.session(id)?.lines.first(where: { $0.id == line.id }) { onLineFixed?(id, now) }+ let before = line.fixes ?? []+ let fixes = known(in: line.src, Correction.merge(before, fresh))+ let dropped = before.filter { $0.applied && $0.user != true && !fixes.contains($0) }.count+ if dropped > 0 { debugLog("fix recheck took back \(dropped) line=\(line.id)") }+ set(fixes, line: line.id, in: id)+ }++ /// The word list's confirmed heard forms, fixed without asking anyone: also with no AI service.+ /// Two characters at least, so a single 压 never turns into 押 everywhere.+ func applyKnown(lineID: String, in id: String) {+ guard settings.fixMisheard, let l = store.session(id)?.lines.first(where: { $0.id == lineID }) else { return }+ set(known(in: l.src, l.fixes ?? []), line: lineID, in: id)+ }++ private func known(in src: String, _ fixes: [LineFix]) -> [LineFix] {+ var out = fixes+ for t in vocabulary.terms {+ // A heard form two words claim (两个都留) is never fixed silently.+ for h in t.heard where h.count >= 2 && src.contains(h) && !refused.contains(Self.pair(h, t.word))+ && vocabulary.owners(ofHeard: h, except: t.word).isEmpty {+ if out.contains(where: { $0.from == h || ($0.applied && $0.from.contains(h)) || ($0.off == true && $0.from == h) }) { continue }+ out.append(LineFix(from: h, to: t.word))+ }+ }+ return out+ }++ private func set(_ fixes: [LineFix], line: String, in id: String) {+ guard let l = store.session(id)?.lines.first(where: { $0.id == line }), fixes != l.fixes ?? [] else { return }+ store.setFixes(in: id, lineID: line, fixes)+ if let now = store.session(id)?.lines.first(where: { $0.id == line }) { onLineFixed?(id, now) }onChange?()}+ // MARK: 待确认+/// 待确认 in a meeting: each (from → to) once, oldest first.func pending(in id: String) -> [(line: TranscriptLine, fix: LineFix)] {var seen: Set<String> = []@@ -80,44 +129,133 @@ final class LiveFixes {return out}+ /// What the notes window's card asks now: not what was put off (稍后再看), and only the first+ /// few, so a burst of names doesn't keep the card up all meeting.+ func asking(in id: String) -> (line: TranscriptLine, fix: LineFix, position: Int, of: Int)? {+ let open = pending(in: id).filter { !deferred.contains(Self.key($0.fix)) }+ guard let first = open.first else { return nil }+ let n = min(open.count, Self.askAtOnce)+ return (first.line, first.fix, 1, n)+ }++ private static func key(_ f: LineFix) -> String { let c = Correction.core(f.from, f.to); return pair(c.from, c.to) }++ /// The notes window's card: asks only while it's useful, and never while the window is shown+ /// to the other side (共享屏幕时让对方看到).+ func later(_ fix: LineFix, in id: String) {+ remember(id, lines: [])+ deferred.insert(Self.key(fix))+ say(L("已收进人名和术语,稍后再看"))+ onChange?()+ }+/// 对 / 不对 on a waiting fix: every line in the meeting waiting on the same change follows,/// and a yes goes into the word list so the next meeting fixes it without asking.func answer(_ fix: LineFix, yes: Bool, in id: String) {let c = Correction.core(fix.from, fix.to)guard let s = store.session(id) else { return }- for l in s.lines {- guard var fixes = l.fixes else { continue }- var changed = false+ let touched = s.lines.filter { ($0.fixes ?? []).contains { $0.ask == true && Correction.core($0.from, $0.to) == c } }+ remember(id, lines: touched.map(\.id))+ for l in touched {+ var fixes = l.fixes ?? []for k in fixes.indices where fixes[k].ask == true && Correction.core(fixes[k].from, fixes[k].to) == c {fixes[k].ask = nil- if !yes { fixes[k].off = true }- changed = true- }- if changed {- store.setFixes(in: id, lineID: l.id, fixes)- if let now = store.session(id)?.lines.first(where: { $0.id == l.id }) { onLineFixed?(id, now) }+ if yes { fixes[k].user = true } else { fixes[k].off = true }}+ set(fixes, line: l.id, in: id)}if yes { vocabulary.confirm(heard: c.from, word: c.to) } else { refused.insert(Self.pair(c.from, c.to)) }debugLog("fix answered \(yes ? "yes" : "no")")- onChange?()+ say(yes ? L("已改 \(c.from) → \(c.to),记进词表") : L("这场不再问 \(c.from)"))}/// 改回: this line goes back to what was heard, and the meeting stops making this change.func revert(_ fix: LineFix, lineID: String, in id: String) {guard let l = store.session(id)?.lines.first(where: { $0.id == lineID }), var fixes = l.fixes,let k = fixes.firstIndex(where: { $0.from == fix.from && $0.to == fix.to }) else { return }+ remember(id, lines: [lineID])fixes[k].off = truefixes[k].ask = nil- store.setFixes(in: id, lineID: lineID, fixes)+ fixes[k].user = nil+ set(fixes, line: lineID, in: id)let c = Correction.core(fix.from, fix.to)refused.insert(Self.pair(c.from, c.to))refused.insert(Self.pair(fix.from, fix.to))let key = Self.pair(c.from, c.to)refusals[key, default: 0] += 1if refusals[key]! >= 2 { vocabulary.forget(heard: c.from, word: c.to) }- if let now = store.session(id)?.lines.first(where: { $0.id == lineID }) { onLineFixed?(id, now) }debugLog("fix reverted line=\(lineID)")+ say(L("已改回 \(c.from),这场不再改"))+ }++ // MARK: 改这句…++ /// How many lines of the meeting the same edit would change ("整场同样听成 木娜 的 2 处都改").+ func sameHeard(lineID: String, in id: String, edited: String) -> (heard: String, count: Int)? {+ guard let s = store.session(id), let l = s.lines.first(where: { $0.id == lineID }),+ let e = Correction.userEdit(shown: l.shown, edited: edited, src: l.src, fixes: l.fixes ?? []) else { return nil }+ let n = s.lines.filter { $0.shown.contains(e.fix.from) }.count+ return (e.heard, max(1, n))+ }++ /// The user rewrote a line (改这句…): what changed becomes their own fix, on this line or on+ /// every line showing the same words, and with `remember` the heard form joins the word list.+ @discardableResult+ func edit(lineID: String, in id: String, to edited: String, everywhere: Bool, remember keep: Bool) -> Int {+ guard let s = store.session(id), let l = s.lines.first(where: { $0.id == lineID }),+ let e = Correction.userEdit(shown: l.shown, edited: edited, src: l.src, fixes: l.fixes ?? []) else { return 0 }+ let targets = everywhere ? s.lines.filter { $0.shown.contains(e.fix.from) } : [l]+ remember(id, lines: targets.map(\.id))+ for t in targets {+ // A guess still waiting on the same words is answered by the edit: not that.+ let fixes = (t.fixes ?? []).map { f -> LineFix in+ var f = f+ if f.ask == true, f.from.contains(e.heard) || e.heard.contains(f.from) { f.ask = nil; f.off = true }+ return f+ }+ set(fixes + [e.fix], line: t.id, in: id)+ }+ let c = Correction.core(e.fix.from, e.fix.to)+ // Only a change made everywhere teaches the word list: a one-off must not.+ if keep, everywhere { vocabulary.confirm(heard: e.heard, word: c.to.trimmingCharacters(in: .whitespaces), source: "user") }+ debugLog("fix edited lines=\(targets.count) keep=\(keep)")+ say(keep ? L("已改 \(targets.count) 处:\(e.heard) → \(c.to.trimmingCharacters(in: .whitespaces)),记进词表")+ : L("已改 \(targets.count) 处:\(e.heard) → \(c.to.trimmingCharacters(in: .whitespaces))"))+ return targets.count+ }++ // MARK: 撤销++ private func remember(_ id: String, lines: [String]) {+ let s = store.session(id)+ var before: [String: [LineFix]] = [:]+ for lid in lines { before[lid] = s?.lines.first { $0.id == lid }?.fixes ?? [] }+ undoStack.append(Step(session: id, lines: before, words: vocabulary.terms, refused: refused, deferred: deferred))+ if undoStack.count > 20 { undoStack.removeFirst() }+ }++ var canUndo: Bool { !undoStack.isEmpty }++ func undo() {+ guard let step = undoStack.popLast() else { return }+ for (lid, fixes) in step.lines {+ store.setFixes(in: step.session, lineID: lid, fixes)+ if let now = store.session(step.session)?.lines.first(where: { $0.id == lid }) { onLineFixed?(step.session, now) }+ }+ vocabulary.restore(step.words)+ refused = step.refused+ deferred = step.deferred+ toast = nil+ debugLog("fix undone")+ onChange?()+ }++ private func say(_ text: String) {+ toast = Toast(text: text)+ toastTimer?.invalidate()+ toastTimer = Timer.scheduledTimer(withTimeInterval: 6, repeats: false) { [weak self] _ in+ MainActor.assumeIsolated { self?.toast = nil }+ }onChange?()}}diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex f9dcac7..4aebdeb 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -24,6 +24,8 @@ struct NotesContentView: View {/// Lines heard since `coveredUntil` that the notes don't cover yet (shown under the last topic).var behind = 0var onJump: (Double) -> Void = { _ in }+ /// 改正听错的词's part of 人名和术语 (the words fixed, the ones waiting), from the notes window.+ var fixTerms: AnyView? = nilvar body: some View {if document {@@ -83,10 +85,11 @@ struct NotesContentView: View {}}- if !notes.terms.isEmpty {+ if !notes.terms.isEmpty || fixTerms != nil {VStack(alignment: .leading, spacing: 10) {title(L("人名和术语"))- TermChips(terms: notes.terms, showHeard: true)+ if let fixTerms { fixTerms }+ if !notes.terms.isEmpty { TermChips(terms: notes.terms, showHeard: true) }}}}@@ -885,6 +888,10 @@ enum TranscriptParagraphs {guard let lo = AttributedString.Index(m.lowerBound, within: a), let hi = AttributedString.Index(m.upperBound, within: a) else { continue }a[lo..<hi].underlineStyle = Text.LineStyle(pattern: .dot, color: Palette.tertiary)}+ // Words waiting for the user (这样改对吗?) get a pale wash, as heard.+ for f in l.fixes ?? [] where f.ask == true {+ if let r = a.range(of: f.from) { a[r].backgroundColor = Palette.accentPale }+ }out += aplain += text}@@ -1437,13 +1444,15 @@ struct FixConfirmCard: View {let fix: LineFixlet count: Intlet onAnswer: (Bool) -> Void+ /// ×: 稍后再看, asked again after the meeting.+ var onLater: (() -> Void)? = nilvar body: some View {let c = Correction.core(fix.from, fix.to)VStack(alignment: .leading, spacing: 8) {HStack(alignment: .firstTextBaseline, spacing: 8) {Text("这样改对吗?").font(.system(size: 13, weight: .semibold))- Text("确认后整场一起改,以后也照此改").font(.system(size: 12)).foregroundStyle(Palette.tertiary).lineLimit(1)+ Text("确认后整场一起改,以后也这样改").font(.system(size: 12)).foregroundStyle(Palette.tertiary).lineLimit(1)Spacer(minLength: 4)if count > 1 { Text("1 / \(count)").font(.system(size: 12).monospacedDigit()).foregroundStyle(Palette.tertiary) }}@@ -1461,6 +1470,13 @@ struct FixConfirmCard: View {Text("不对").font(.system(size: 13)).foregroundStyle(Palette.secondary).padding(.horizontal, 14).frame(height: 28).background(RoundedRectangle(cornerRadius: 7).fill(Palette.fill))}.buttonStyle(.plain)+ if let onLater {+ Button(action: onLater) {+ Image(systemName: "xmark").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.tertiary)+ .frame(width: 26, height: 28).contentShape(Rectangle())+ }+ .buttonStyle(.plain).help(L("稍后再看")).accessibilityLabel(L("稍后再看"))+ }}}.padding(.horizontal, 12).padding(.vertical, 10)@@ -1469,3 +1485,76 @@ struct FixConfirmCard: View {.shadow(color: .black.opacity(0.08), radius: 10, y: 4)}}++/// 人名和术语, the fixing part: each word fixed in this meeting with what it was heard as and how+/// often (a click shows those lines), and the names still waiting, with ✓ and ×.+struct FixTermsView: View {+ @ObservedObject var fixes: LiveFixes+ let session: Session+ let onShow: (String) -> Void++ var body: some View {+ let words = Self.fixedWords(session)+ let waiting = fixes.pending(in: session.id)+ VStack(alignment: .leading, spacing: 8) {+ if !words.isEmpty {+ FlowLayout(spacing: 6) {+ ForEach(words, id: \.word) { w in+ Button { onShow(w.word) } label: {+ VStack(alignment: .leading, spacing: 1) {+ Text(w.word).font(.system(size: 12)).bold().foregroundStyle(Palette.ink)+ Text("听成 \(w.heard.prefix(2).joined(separator: "、")) · 改了 \(w.count) 处")+ .font(.system(size: 11)).foregroundStyle(Palette.link)+ }+ .padding(.horizontal, 9).padding(.vertical, 5)+ .background(RoundedRectangle(cornerRadius: 7).fill(Palette.fill))+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ }+ }+ }+ if !waiting.isEmpty {+ Text("等你确认,还没改").font(.system(size: 12)).foregroundStyle(Palette.tertiary).padding(.top, 2)+ ForEach(Array(waiting.enumerated()), id: \.offset) { _, w in+ let c = Correction.core(w.fix.from, w.fix.to)+ HStack(spacing: 8) {+ VStack(alignment: .leading, spacing: 1) {+ Text(c.to).font(.system(size: 13)).bold()+ Text("听成 \(c.from)").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ }+ Spacer(minLength: 4)+ Button { fixes.answer(w.fix, yes: true, in: session.id) } label: {+ Image(systemName: "checkmark").font(.system(size: 12, weight: .semibold)).foregroundStyle(.white)+ .frame(width: 28, height: 28).background(RoundedRectangle(cornerRadius: 7).fill(Palette.ink))+ }+ .buttonStyle(.plain).accessibilityLabel(L("对"))+ Button { fixes.answer(w.fix, yes: false, in: session.id) } label: {+ Image(systemName: "xmark").font(.system(size: 12, weight: .semibold)).foregroundStyle(Palette.secondary)+ .frame(width: 28, height: 28).background(RoundedRectangle(cornerRadius: 7).fill(Palette.fill))+ }+ .buttonStyle(.plain).accessibilityLabel(L("不对"))+ }+ .padding(.leading, 10).padding(.trailing, 6).padding(.vertical, 5)+ .overlay(RoundedRectangle(cornerRadius: 9).strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [3, 3])).foregroundStyle(Color(white: 0.8)))+ }+ }+ }+ }++ /// The words fixed in a meeting, most fixed first: what each was heard as, and how often.+ static func fixedWords(_ s: Session) -> [(word: String, heard: [String], count: Int)] {+ var out: [String: (heard: [String], count: Int)] = [:]+ for l in s.lines {+ for f in l.fixes ?? [] where f.applied {+ let c = Correction.core(f.from, f.to)+ let word = c.to.trimmingCharacters(in: .whitespaces)+ var e = out[word] ?? ([], 0)+ if !e.heard.contains(c.from) { e.heard.append(c.from) }+ e.count += 1+ out[word] = e+ }+ }+ return out.map { ($0.key, $0.value.heard, $0.value.count) }.sorted { $0.count > $1.count }+ }+}diff --git a/Sources/Cicada/NotesWindow.swift b/Sources/Cicada/NotesWindow.swiftindex b6970a5..e8e419c 100644--- a/Sources/Cicada/NotesWindow.swift+++ b/Sources/Cicada/NotesWindow.swift@@ -290,6 +290,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) }+ .overlay(alignment: .bottom) { FixToast(fixes: model.fixes).padding(.bottom, 14) }}}.frame(width: geo.size.width, height: geo.size.height)@@ -866,7 +867,8 @@ struct NotesWindowView: View {coveredUntil: lastCovered > 0 ? lastCovered : nil,endedAt: session?.lines.last?.t,behind: behind,- onJump: { t in jumpTo = t; tab = "transcript" })+ onJump: { t in jumpTo = t; tab = "transcript" },+ fixTerms: fixTermsView).padding(.horizontal, 24).padding(.top, 16).padding(.bottom, 12)}.topFade()@@ -892,17 +894,20 @@ struct NotesWindowView: View {if animated { withAnimation(.easeInOut(duration: 0.4)) { proxy.scrollTo(id, anchor: .top) } } else { proxy.scrollTo(id, anchor: .top) }}+ /// Not while the window is shown to the other side: names wait in 人名和术语 then.@ViewBuilder private var fixAsk: some View {- if let s = session {- let waiting = model.fixes.pending(in: s.id)- if let first = waiting.first {- FixConfirmCard(line: first.line, fix: first.fix, count: waiting.count) { yes in- model.fixes.answer(first.fix, yes: yes, in: s.id)- }- }+ if let s = session, !model.settings.notesCapturable, let a = model.fixes.asking(in: s.id) {+ FixConfirmCard(line: a.line, fix: a.fix, count: a.of, onAnswer: { yes in+ model.fixes.answer(a.fix, yes: yes, in: s.id)+ }, onLater: { model.fixes.later(a.fix, in: s.id) })}}+ private var fixTermsView: AnyView? {+ guard let s = session, !FixTermsView.fixedWords(s).isEmpty || !model.fixes.pending(in: s.id).isEmpty else { return nil }+ return AnyView(FixTermsView(fixes: model.fixes, session: s) { word in query = word; tab = "transcript" })+ }+private var transcript: some View {let ms = matcheslet lines = session?.lines ?? []diff --git a/Sources/Cicada/Translator.swift b/Sources/Cicada/Translator.swiftindex 2539b7d..5940d31 100644--- a/Sources/Cicada/Translator.swift+++ b/Sources/Cicada/Translator.swift@@ -104,6 +104,10 @@ final class TranslationService {var words: [String]/// The lines just before, as shown.var recent: [String]+ /// On a second pass: the lines after it, which often tell what a word was.+ var following: [String] = []+ /// The notes' summary so far, once there is one.+ var summary: String? = nil}var fixContext: ((_ text: String) -> FixContext?)?/// The fixes the service proposed for a sentence it translated (by its text as heard).@@ -288,7 +292,9 @@ final class TranslationService {if !ctx.words.isEmpty { prompt += "\nThe user's word list (spellings to use): " + ctx.words.joined(separator: "; ") }let names = glossary()if !names.isEmpty { prompt += "\nNames the notes guessed (not confirmed): " + names.joined(separator: "; ") }+ if let summary = ctx.summary, !summary.isEmpty { prompt += "\nThe meeting so far: " + summary }if !ctx.recent.isEmpty { prompt += "\nLines just before:\n" + ctx.recent.joined(separator: "\n") }+ if !ctx.following.isEmpty { prompt += "\nLines just after:\n" + ctx.following.joined(separator: "\n") }prompt += "\nSubtitle: " + textdo {let out = try await ling.chat(content: prompt, instruction: "JSON only.", priority: kind == .file ? .notes : .translate,@@ -305,7 +311,8 @@ final class TranslationService {guard !parsed.translation.isEmpty, let clean = Self.cleanTranslation(parsed.translation, target: target) else {return (nil, "remark")}- if !parsed.edits.isEmpty { onFixes?(text, parsed.edits) }+ // None proposed is an answer too: a second pass takes back what it no longer proposes.+ onFixes?(text, parsed.edits)return (clean, "")} catch {debugLog("translate ling failed: \(error)")diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swiftindex a5c8168..3b12193 100644--- a/Sources/Cicada/Views.swift+++ b/Sources/Cicada/Views.swift@@ -797,6 +797,10 @@ struct MainWindowView: View {/// The bilingual column beside the notes is opt-in: three full columns of text read as crowded.@AppStorage("mainShowQuotes") private var showQuotes = false@State private var showOlder = false+ /// 改这句…: the line being rewritten, and what the editor opens with.+ @State private var editingLine: String?+ @State private var editingStart = ""+ @State private var hoveredLine: String?/// Wide enough for the notes and the bilingual transcript side by side.private var sideBySide: Bool { showQuotes && wideEnough }@@ -1320,10 +1324,18 @@ struct MainWindowView: View {let starts = SpeakerLabels.runStarts(s.lines, speakers).union(both ? RecordList.placeStarts(s.lines) : [])let voices = SpeakerLabels.voiceNumbers(s.lines)let playingLine = player.lineID(in: s)+ if 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) })+ .padding(.bottom, 10)+ }ForEach(s.lines) { l inlineRow(l, speaker: speakers[l.id], label: speakers.isEmpty || starts.contains(l.id), voices: !speakers.isEmpty, place: both, in: s,current: l.id == playingLine)- .contextMenu { if !speakers.isEmpty, l.speaker == "them" { assignMenu(s, l, voices) } }+ .contextMenu {+ Button(L("改这句…")) { editingStart = l.shown; editingLine = l.id }+ if !speakers.isEmpty, l.speaker == "them" { assignMenu(s, l, voices) }+ }.id(l.id)}}@@ -1338,6 +1350,7 @@ struct MainWindowView: View {if pinned { pinnedBar(s) { withAnimation { proxy.scrollTo(PinnedHeader.top, anchor: .top) } } }}.animation(.easeOut(duration: 0.15), value: pinned)+ .overlay(alignment: .bottom) { FixToast(fixes: model.fixes).padding(.bottom, 18) }.onChange(of: s.lines.count) { _, _ inif s.id == store.liveID, let last = s.lines.last {withAnimation { proxy.scrollTo(last.id, anchor: .bottom) }@@ -1390,8 +1403,10 @@ struct MainWindowView: View {}if place, label, !me { PlaceTag(line: l) }}- if view != "dst" {- Text(l.shown)+ 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])).font(.system(size: view == "src" ? 15 : 13)).foregroundStyle(view == "src" ? Palette.ink : Palette.tertiary).lineSpacing(2)@@ -1403,9 +1418,21 @@ struct MainWindowView: View {.foregroundStyle(l.dst == nil ? Palette.tertiary : Palette.ink).textSelection(.enabled)}+ // Pointing at a line: what its fixed words were heard as, 改回, and 改这句….+ if hoveredLine == l.id, editingLine != l.id, let s = shownSession {+ HStack(spacing: 8) {+ let fixed = (l.fixes ?? []).filter(\.applied).map { (l.id, $0) }+ if !fixed.isEmpty { FixedWords(fixes: fixed) { id, f in model.fixes.revert(f, lineID: id, in: s.id) } }+ Button(L("改这句…")) { editingStart = l.shown; editingLine = l.id }+ .buttonStyle(.plain).font(.system(size: 11, weight: .medium)).foregroundStyle(Palette.link)+ }+ .padding(.top, 2)+ }}Spacer(minLength: 0)}+ .contentShape(Rectangle())+ .onHover { inside in if inside { hoveredLine = l.id } else if hoveredLine == l.id { hoveredLine = nil } }.padding(.vertical, 12)// The line the recording is playing..background(RoundedRectangle(cornerRadius: 10).fill(current ? Palette.accentPale : .clear).padding(.horizontal, -10))diff --git a/Sources/Cicada/Vocabulary.swift b/Sources/Cicada/Vocabulary.swiftindex 5a63752..2244a3c 100644--- a/Sources/Cicada/Vocabulary.swift+++ b/Sources/Cicada/Vocabulary.swift@@ -66,6 +66,52 @@ final class Vocabulary: ObservableObject {save()}+ /// 词表 › click a word: its spelling changes; what it was heard as stays with it.+ func rename(_ word: String, to new: String) {+ let n = new.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !n.isEmpty, n.count <= 40, let i = terms.firstIndex(where: { Self.key($0.word) == Self.key(word) }) else { return }+ if let j = terms.firstIndex(where: { Self.key($0.word) == Self.key(n) }), j != i {+ // Renamed onto a word already there: the two become one.+ for h in terms[i].heard where !terms[j].heard.contains(where: { Self.key($0) == Self.key(h) }) { terms[j].heard.append(h) }+ terms.remove(at: i)+ } else {+ terms[i].word = n+ }+ save()+ }++ /// The other words a heard form already belongs to ("莫拉" is Morpho's).+ func owners(ofHeard heard: String, except word: String? = nil) -> [String] {+ terms.filter { t in t.heard.contains { Self.key($0) == Self.key(heard) } && Self.key(t.word) != Self.key(word ?? "") }.map(\.word)+ }++ /// Back where it was, after 撤销 on a delete.+ func insert(_ term: Term, at index: Int) {+ guard !terms.contains(where: { Self.key($0.word) == Self.key(term.word) }) else { return }+ terms.insert(term, at: min(index, terms.count))+ save()+ }++ /// What 粘贴导入 would do, before it does it (the sheet's counts and its button).+ func preview(_ text: String) -> ImportResult {+ var r = ImportResult()+ var seen: Set<String> = []+ for case let entry? in Self.parse(text) {+ if entry.word.isEmpty { r.skipped.append(entry.line); continue }+ let k = Self.key(entry.word)+ if terms.contains(where: { Self.key($0.word) == k }) || seen.contains(k) { r.updated += 1 } else { r.added += 1 }+ seen.insert(k)+ }+ return r+ }++ /// 撤销: the list as it was.+ func restore(_ saved: [Term]) {+ guard saved != terms else { return }+ terms = saved+ save()+ }+func remove(_ word: String) {terms.removeAll { Self.key($0.word) == Self.key(word) }save()diff --git a/Tests/CicadaTests/CorrectionTests.swift b/Tests/CicadaTests/CorrectionTests.swiftindex 0b220a4..1a5f376 100644--- a/Tests/CicadaTests/CorrectionTests.swift+++ b/Tests/CicadaTests/CorrectionTests.swift@@ -103,6 +103,28 @@ import Testing#expect(Correction.merge(old, new) == [LineFix(from: "莫拉", to: "Morpho", off: true), LineFix(from: "寻检", to: "巡检")])}+ @Test func recheckTakesBackWhatItNoLongerProposesButNotTheUsers() {+ let old = [LineFix(from: "跑好的", to: "跑跑的"), LineFix(from: "开布特", to: "Curve", user: true)]+ // The recheck proposes nothing: the model's guess goes, the user's yes stays.+ #expect(Correction.merge(old, []) == [LineFix(from: "开布特", to: "Curve", user: true)])+ // Nor can it override the user's word with another.+ #expect(Correction.merge(old, [LineFix(from: "开布特", to: "Cobalt")]) == [LineFix(from: "开布特", to: "Curve", user: true)])+ }++ @Test func userEditOnTopOfAFix() {+ let fixes = [LineFix(from: "莫纳", to: "Morpho")]+ let src = "扩展到这个莫纳的 Link"+ let shown = Correction.apply(fixes, to: src).text+ let e = Correction.userEdit(shown: shown, edited: "扩展到这个Monad的 Link", src: src, fixes: fixes)+ #expect(e?.fix == LineFix(from: "Morpho", to: "Monad", user: true))+ #expect(e?.heard == "莫纳")+ #expect(Correction.apply(fixes + [e!.fix], to: src).text == "扩展到这个Monad的 Link")+ // A plain heard word.+ let p = Correction.userEdit(shown: "我木娜找了一个", edited: "我在 Monad 找了一个", src: "我木娜找了一个", fixes: [])+ #expect(p?.heard == "木娜")+ #expect(Correction.userEdit(shown: "a", edited: " a ", src: "a", fixes: []) == nil)+ }+@Test func recordFormatUnchangedWithoutFixes() throws {let line = TranscriptLine(id: "1", t: 0, speaker: "them", src: "a", dst: nil, srcLang: "zh", dstLang: "en")let json = String(data: try JSONEncoder().encode(line), encoding: .utf8)!diff --git a/Tests/CicadaTests/LiveFixesTests.swift b/Tests/CicadaTests/LiveFixesTests.swiftnew file mode 100644index 0000000..5f87937--- /dev/null+++ b/Tests/CicadaTests/LiveFixesTests.swift@@ -0,0 +1,86 @@+import Foundation+import Testing+@testable import Cicada++/// Who wins on a line: the user's decisions, then the word list, then the recheck, then the first guess.+@MainActor @Suite struct LiveFixesTests {+ private func setup(_ lines: [String]) -> (LiveFixes, SessionStore, String) {+ let root = FileManager.default.temporaryDirectory.appendingPathComponent("fixes-\(UUID().uuidString)")+ let store = SessionStore(root: root)+ let s = store.begin()+ for (i, t) in lines.enumerated() {+ store.append(TranscriptLine(id: "l\(i)", t: Double(i), speaker: "them", src: t, dst: nil, srcLang: "zh-CN", dstLang: "en"))+ }+ let settings = AppSettings()+ settings.fixMisheard = true+ settings.askNames = true+ return (LiveFixes(store: store, vocabulary: Vocabulary(url: nil), settings: settings), store, s.id)+ }++ private func line(_ store: SessionStore, _ id: String, _ l: String) -> TranscriptLine {+ store.session(id)!.lines.first { $0.id == l }!+ }++ @Test func recheckTakesBackAGuessButKeepsTheUsersYes() {+ let (fx, store, id) = setup(["最近那个开布特提了,这个是跑好的测试"])+ let text = line(store, id, "l0").src+ fx.received(text, [.init(from: "开布特", to: "Curve", confidence: 0.9), .init(from: "跑好的", to: "跑跑的", confidence: 0.9)])+ #expect(line(store, id, "l0").shown.contains("跑跑的"))+ fx.answer(fx.pending(in: id)[0].fix, yes: true, in: id)+ #expect(line(store, id, "l0").shown == "最近那个Curve提了,这个是跑跑的测试")+ // The recheck, with the lines after it in view, proposes nothing.+ fx.received(text, [])+ #expect(line(store, id, "l0").shown == "最近那个Curve提了,这个是跑好的测试")+ }++ @Test func confirmedHeardFormsApplyWithoutTheService() {+ let (fx, store, id) = setup(["扩展到这个莫拉的链", "单个的拉不改"])+ fx.vocabulary.confirm(heard: "莫拉", word: "Morpho")+ fx.applyKnown(lineID: "l0", in: id)+ fx.applyKnown(lineID: "l1", in: id)+ #expect(line(store, id, "l0").shown == "扩展到这个Morpho的链")+ #expect(line(store, id, "l1").fixes == nil)+ }++ @Test func editEverywhereTeachesTheListAndUndoPutsItBack() {+ let (fx, store, id) = setup(["我木娜找了一个", "木娜那边也有", "别的"])+ #expect(fx.sameHeard(lineID: "l0", in: id, edited: "我Monad找了一个")?.count == 2)+ let n = fx.edit(lineID: "l0", in: id, to: "我Monad找了一个", everywhere: true, remember: true)+ #expect(n == 2)+ #expect(line(store, id, "l1").shown == "Monad那边也有")+ #expect(fx.vocabulary.knows(heard: "木娜", word: "Monad"))+ // A later pass can't override what the user wrote.+ fx.received(line(store, id, "l1").src, [.init(from: "木娜", to: "Mona", confidence: 0.95)])+ #expect(line(store, id, "l1").shown == "Monad那边也有")+ fx.undo()+ #expect(line(store, id, "l0").shown == "我木娜找了一个")+ #expect(!fx.vocabulary.knows(heard: "木娜", word: "Monad"))+ }++ @Test func oneOffEditDoesNotTeachTheList() {+ let (fx, store, id) = setup(["我木娜找了一个", "木娜那边也有"])+ fx.edit(lineID: "l0", in: id, to: "我Monad找了一个", everywhere: false, remember: true)+ #expect(line(store, id, "l1").shown == "木娜那边也有")+ #expect(fx.vocabulary.terms.isEmpty)+ }++ @Test func laterTakesItOffTheCardButKeepsItWaiting() {+ let (fx, _, id) = setup(["最近那个开布特提了"])+ fx.received("最近那个开布特提了", [.init(from: "开布特", to: "Curve", confidence: 0.9)])+ let a = fx.asking(in: id)!+ fx.later(a.fix, in: id)+ #expect(fx.asking(in: id) == nil)+ #expect(fx.pending(in: id).count == 1)+ fx.undo()+ #expect(fx.asking(in: id) != nil)+ }++ @Test func revertStaysRevertedThroughTheRecheck() {+ let (fx, store, id) = setup(["但质压这种"])+ fx.received("但质压这种", [.init(from: "质压", to: "质押", confidence: 0.9)])+ let f = line(store, id, "l0").fixes![0]+ fx.revert(f, lineID: "l0", in: id)+ fx.received("但质压这种", [.init(from: "质压", to: "质押", confidence: 0.9)])+ #expect(line(store, id, "l0").shown == "但质压这种")+ }+}diff --git a/Tests/CicadaTests/VocabularyTests.swift b/Tests/CicadaTests/VocabularyTests.swiftindex 53d3501..e3ca8be 100644--- a/Tests/CicadaTests/VocabularyTests.swift+++ b/Tests/CicadaTests/VocabularyTests.swift@@ -42,4 +42,21 @@ import Testing_ = v.importText("Morpho = 莫拉")#expect(Vocabulary(url: url).knows(heard: "莫拉", word: "Morpho"))}++ @Test func renameKeepsHeardFormsAndMerges() {+ let v = Vocabulary(url: nil)+ _ = v.importText("Morfo = 莫拉\nMorpho = 莫法")+ v.rename("Morfo", to: "Morpho")+ #expect(v.terms.count == 1)+ #expect(v.knows(heard: "莫拉", word: "Morpho") && v.knows(heard: "莫法", word: "Morpho"))+ }++ @Test func ownersAndPreview() {+ let v = Vocabulary(url: nil)+ _ = v.importText("Morpho = 莫拉")+ #expect(v.owners(ofHeard: "莫拉", except: "Mora") == ["Morpho"])+ #expect(v.owners(ofHeard: "莫拉", except: "Morpho").isEmpty)+ #expect(v.preview("Morpho = 莫法\nPendle\n" + String(repeating: "长", count: 41)) == .init(added: 1, updated: 1, skipped: [3]))+ #expect(v.terms.count == 1)+ }}diff --git a/site/changelog.json b/site/changelog.jsonindex 3b8efd2..9f97438 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -29,6 +29,14 @@],"title": "设置里多了“词表”:常用的人名、产品名一次贴进来,会中就照这些写法改。","text": "一行一个,常被听错的写法写在 = 后面(Morpho = 莫拉)。会中答“对”的词也会记进来,标着“会中确认”和改过几次。词表只存在这台 Mac 上,只发文字给你选的 AI 服务。"+ },+ {+ "kind": "new",+ "platforms": [+ "mac"+ ],+ "title": "会议记录里可以自己改听错的词:右键或指着一句选“改这句…”,整场同样听错的地方一起改,并记进词表。",+ "text": "会议结束后,文字记录顶部会逐个问还没确认的改法(对 / 不对 / 改成…)。每次改动、改回、确认之后都有“撤销”。每句说完十几秒后知了会带着后面几句再看一遍,补上漏改的、撤掉改错的,但你确认过、改过的地方不会被动。纪要窗口的“这样改对吗?”可以先按 × 放一放,留到会后再问;人名和术语里能看到每个词改了几处,点一下就跳到那几句。"}]},