知了 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: corrected words under Names and terms in the notes window no longer swap places every second
wqugurub4215c5f64e9
diff --git a/Sources/Cicada/Diagnostics.swift b/Sources/Cicada/Diagnostics.swiftindex ce0b986..75b7ffe 100644--- a/Sources/Cicada/Diagnostics.swift+++ b/Sources/Cicada/Diagnostics.swift@@ -189,6 +189,8 @@ final class Diagnostics: ObservableObject {/// The uses shown, in this order; test scores and file imports only count in the totals.static let roles = ["translate", "heard-me", "voice", "notes", "speakers"]+ // Every list below is grouped through a Dictionary, whose order changes with each instance;+ // the page redraws every 2 s, so ties are broken by name or rows would swap.var uses: [Use] {Dictionary(grouping: calls.filter { Self.roles.contains($0.role) }) { "\($0.role)|\($0.provider)|\($0.model)" }.values.compactMap { xs -> Use? in@@ -202,11 +204,11 @@ final class Diagnostics: ObservableObject {latency: Self.stat(c.role == "voice" ? ok.compactMap(\.firstAudio) : ok.map(\.seconds)),tokens: xs.reduce(0) { $0 + $1.promptTokens + $1.completionTokens },chars: xs.reduce(0) { $0 + $1.chars },- reasons: reasons.sorted { $0.value > $1.value }.map { ($0.key, $0.value) })+ reasons: reasons.sorted { ($0.value, $1.key) > ($1.value, $0.key) }.map { ($0.key, $0.value) })}.sorted { a, b inlet (i, j) = (Self.roles.firstIndex(of: a.role) ?? 99, Self.roles.firstIndex(of: b.role) ?? 99)- return i != j ? i < j : a.n > b.n+ return i != j ? i < j : a.n != b.n ? a.n > b.n : (a.provider, a.model) < (b.provider, b.model)}}@@ -214,7 +216,7 @@ final class Diagnostics: ObservableObject {var retreats: [(String, Int)] {let services = Set(AIProvider.all.map(\.id.rawValue))let xs = sentences.filter { s in s.fallbacks.contains { services.contains(String($0.split(separator: ":").first ?? "")) } }- return Dictionary(grouping: xs, by: \.via).map { ($0.key, $0.value.count) }.sorted { $0.1 > $1.1 }+ return Dictionary(grouping: xs, by: \.via).map { ($0.key, $0.value.count) }.sorted { ($0.1, $1.0) > ($1.1, $0.0) }}var voiceChars: Int { calls.filter { $0.role == "voice" }.reduce(0) { $0 + $1.chars } }@@ -222,7 +224,7 @@ final class Diagnostics: ObservableObject {var viaCounts: [(String, Int, Double)] {Dictionary(grouping: sentences, by: \.via).map { via, xs in(via, xs.count, Self.stat(xs.map(\.translate))?.p50 ?? 0)- }.sorted { $0.1 > $1.1 }+ }.sorted { ($0.1, $1.0) > ($1.1, $0.0) }}/// Why the AI service (or Google) was passed over: hijacked, rateLimited, timeout…@@ -230,7 +232,7 @@ final class Diagnostics: ObservableObject {var counts: [String: Int] = [:]for s in sentences { for f in s.fallbacks { counts[f, default: 0] += 1 } }for c in calls where c.outcome == "rateLimited" && c.role == "notes" { counts["notes:rateLimited", default: 0] += 1 }- return counts.sorted { $0.value > $1.value }.map { ($0.key, $0.value) }+ return counts.sorted { ($0.value, $1.key) > ($1.value, $0.key) }.map { ($0.key, $0.value) }}/// Requests started in the last 10 s, per second (a Ling account allows about 2).diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex 7e7b748..e87d216 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -1555,6 +1555,9 @@ struct FixTermsView: View {out[word] = e}}- return out.map { ($0.key, $0.value.heard, $0.value.count) }.sorted { $0.count > $1.count }+ // Ties by word: a Dictionary's order differs with each instance, and this runs on every+ // redraw (the window ticks each second), so the chips would swap places.+ return out.map { ($0.key, $0.value.heard, $0.value.count) }+ .sorted { $0.count != $1.count ? $0.count > $1.count : $0.word < $1.word }}}diff --git a/Tests/CicadaTests/NotesTests.swift b/Tests/CicadaTests/NotesTests.swiftindex edbfa82..b2c7cd7 100644--- a/Tests/CicadaTests/NotesTests.swift+++ b/Tests/CicadaTests/NotesTests.swift@@ -164,4 +164,17 @@ import Testing#expect(NotesEngine.subject("Budget review (cont.)") == "Budget review")#expect(NotesEngine.subject("(续)") == "(续)")}++ @Test func fixedWordsKeepOneOrderAcrossRedraws() {+ var lines: [TranscriptLine] = []+ for (i, w) in ["王总", "Kubernetes", "李雷", "OpenAI", "张三", "Cicada", "李雷"].enumerated() {+ var l = TranscriptLine(id: "l\(i)", t: Double(i), speaker: "them", src: w, dst: nil, srcLang: "zh-CN", dstLang: "en")+ l.fixes = [LineFix(from: "x\(i)", to: w)]+ lines.append(l)+ }+ let s = Session(id: "s", title: "t", startedAt: Date(), endedAt: nil, lines: lines, hasAudio: false)+ let first = FixTermsView.fixedWords(s).map(\.word)+ #expect(first == ["李雷", "Cicada", "Kubernetes", "OpenAI", "张三", "王总"])+ for _ in 0..<20 { #expect(FixTermsView.fixedWords(s).map(\.word) == first) }+ }}