知了 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: Revert and the heard-as chips name an added word whole (in → in now), not "→ now" with nothing before the arrow
wqugurucc718cc16727
diff --git a/Sources/Cicada/Correction.swift b/Sources/Cicada/Correction.swiftindex 097237c..de03eaf 100644--- a/Sources/Cicada/Correction.swift+++ b/Sources/Cicada/Correction.swift@@ -57,6 +57,13 @@ enum Correction {return (String(a[i..<(a.count - j)]), String(b[i..<(b.count - j)]))}+ /// A fix as the UI names it (听成 X → Y, 已改回 X): the changed words, or the whole fix when+ /// it only adds or drops words ("in" → "in now", whose changed part alone would be "" → "now").+ static func label(_ f: LineFix) -> (from: String, to: String) {+ let c = core(f.from, f.to)+ return c.from.isEmpty || c.to.isEmpty ? (f.from, f.to) : c+ }+/// `known`: the user confirmed this heard form for this word (the word list). `rejected`: they/// said no to it in this meeting.static func decide(_ e: Edit, known: (String, String) -> Bool, rejected: (String, String) -> Bool) -> Verdict {diff --git a/Sources/Cicada/FixViews.swift b/Sources/Cicada/FixViews.swiftindex b487827..00a2a36 100644--- a/Sources/Cicada/FixViews.swift+++ b/Sources/Cicada/FixViews.swift@@ -75,7 +75,7 @@ struct FixReviewBanner: 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)+ let c = Correction.label(first.fix)HStack(spacing: 10) {Button { onShow(first.line.id) } label: {VStack(alignment: .leading, spacing: 2) {diff --git a/Sources/Cicada/LiveFixes.swift b/Sources/Cicada/LiveFixes.swiftindex c7eb3e2..b803f12 100644--- a/Sources/Cicada/LiveFixes.swift+++ b/Sources/Cicada/LiveFixes.swift@@ -201,7 +201,7 @@ final class LiveFixes: ObservableObject {refusals[key, default: 0] += 1if refusals[key]! >= 2 { vocabulary.forget(heard: c.from, word: c.to) }debugLog("fix reverted line=\(lineID)")- say(L("已改回 \(c.from),这场不再改"))+ say(L("已改回 \(Correction.label(fix).from),这场不再改"))}// MARK: 改这句…diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex 486c902..7e7b748 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -1423,7 +1423,7 @@ struct FixedWords: View {var body: some View {FlowLayout(spacing: 6) {ForEach(Array(fixes.enumerated()), id: \.offset) { _, item in- let c = Correction.core(item.fix.from, item.fix.to)+ let c = Correction.label(item.fix)HStack(spacing: 6) {(Text("听成").foregroundStyle(Palette.tertiary) + Text(" " + c.from) + Text(" → ").foregroundStyle(Palette.tertiary) + Text(c.to)).font(.system(size: 11))@@ -1448,7 +1448,7 @@ struct FixConfirmCard: View {var onLater: (() -> Void)? = nilvar body: some View {- let c = Correction.core(fix.from, fix.to)+ let c = Correction.label(fix)VStack(alignment: .leading, spacing: 8) {HStack(alignment: .firstTextBaseline, spacing: 8) {Text("这样改对吗?").font(.system(size: 13, weight: .semibold))@@ -1517,7 +1517,7 @@ struct FixTermsView: View {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)+ let c = Correction.label(w.fix)HStack(spacing: 8) {VStack(alignment: .leading, spacing: 1) {Text(c.to).font(.system(size: 13)).bold()@@ -1547,7 +1547,7 @@ struct FixTermsView: View {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 c = Correction.label(f)let word = c.to.trimmingCharacters(in: .whitespaces)var e = out[word] ?? ([], 0)if !e.heard.contains(c.from) { e.heard.append(c.from) }diff --git a/Tests/CicadaTests/CorrectionTests.swift b/Tests/CicadaTests/CorrectionTests.swiftindex ce308d7..78ef1ed 100644--- a/Tests/CicadaTests/CorrectionTests.swift+++ b/Tests/CicadaTests/CorrectionTests.swift@@ -158,4 +158,10 @@ import Testing// A real swap is still a swap.#expect(Correction.userEdit(shown: "我木娜找了", edited: "我Monad找了", src: "我木娜找了", fixes: [])?.swap == true)}++ @Test func labelNamesAnAddedWordWhole() {+ #expect(Correction.label(LineFix(from: "in", to: "in now", user: true)) == ("in", "in now"))+ #expect(Correction.label(LineFix(from: "Great", to: "OK Great", user: true)) == ("Great", "OK Great"))+ #expect(Correction.label(LineFix(from: "解除质压", to: "解除质押")) == ("质压", "质押"))+ }}