知了 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: a short reply in a voice not yet known no longer joins the answer before it in the live transcript
wquguruab787d4ad960
diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 654db45..55327b1 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -126,6 +126,8 @@ final class AppModel: ObservableObject {@Published var liveSource = ""/// Lines whose words the record's own recognizer hasn't settled yet (the notes window says 校准中).@Published private(set) var settling: Set<String> = []+ /// Lines whose voiceprint is still being worked out: no voice yet is not "like no voice".+ @Published private(set) var voicePending: Set<String> = []@Published var liveTranslation = ""@Published var onboardingStep = 1/// Step 3 is showing what skipping the key leaves out (debug: `onboarding:3,skip`).@@ -669,6 +671,7 @@ final class AppModel: ObservableObject {heldJoin = nilrefining = [:]settling = []+ voicePending = []refiningOrder = []lineOfSegment = [:]settledEarly = [:]@@ -1527,6 +1530,7 @@ final class AppModel: ObservableObject {if let held = heldJoin {heldJoin = nilappendHeard(held.seg, t: held.t, translation: held.translation)+ if let line = lineForSegment[held.seg.id] { voicePending.insert(line) }}guard let prev = lastHeard, store.session(store.liveID ?? "")?.lines.last?.id == prev.line,prev.seg.clock == seg.clock, prev.seg.sourceCode == seg.sourceCode,@@ -1549,7 +1553,10 @@ final class AppModel: ObservableObject {private func heardVoice(_ seg: Segment, _ voice: Int?) {guard let held = heldJoin, held.seg.id == seg.id else {// Already recorded on its own (another line came first).- if let voice, let line = lineForSegment[seg.id] { speakers.onVoice?(line, voice) }+ if let line = lineForSegment[seg.id] {+ if let voice { speakers.onVoice?(line, voice) }+ voicePending.remove(line)+ }return}heldJoin = nil@@ -1596,7 +1603,8 @@ final class AppModel: ObservableObject {lastHeard = (kept, id)// A line with hardly a letter ("." from a breath or a click) gets no voiceprint.if tag, settings.speakerVoices, let samples = seg.voiceSamples, seg.text.filter(\.isLetter).count >= 2 {- speakers.tag(lineID: id, samples: samples)+ voicePending.insert(id)+ speakers.tag(lineID: id, samples: samples) { [weak self] in self?.voicePending.remove(id) }}heardWords()}diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swiftindex 3d14c59..12f3938 100644--- a/Sources/Cicada/NotesViews.swift+++ b/Sources/Cicada/NotesViews.swift@@ -537,6 +537,8 @@ struct TranscriptListView<Partial: View>: View, Equatable {var places = false/// Lines the meeting record's own recognizer is still settling: their words may change.var settling: Set<String> = []+ /// Lines whose voice is still being heard (`AppModel.voicePending`).+ var voicePending: Set<String> = []var onAssign: ((Set<String>, Int) -> Void)?/// 改回 on a fixed word: the line goes back to what was heard.var onRevert: ((String, LineFix) -> Void)?@@ -556,6 +558,7 @@ struct TranscriptListView<Partial: View>: View, Equatable {&& 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.voices == b.voices && a.marked == b.marked&& a.identifying == b.identifying && a.places == b.places && a.settling == b.settling+ && a.voicePending == b.voicePending}private var searching: Bool { !terms.isEmpty }@@ -590,7 +593,7 @@ struct TranscriptListView<Partial: View>: View, Equatable {var out: [Item] = []for (gi, g) in gs.enumerated() {if !g.title.isEmpty { out.append(.header(title: g.title, start: g.start, gap: gi > 0)) }- for (i, p) in TranscriptParagraphs.group(g.lines, speakers).enumerated() {+ for (i, p) in TranscriptParagraphs.group(g.lines, speakers, pending: voicePending).enumerated() {// With voices told apart, a name only where the speaker changes (and atop each topic).// Every paragraph carries its name when voices are on: it is also where it's corrected.out.append(.paragraph(p, label: speakers.isEmpty || !voices.isEmpty || i == 0 || starts.contains(p[0].id)))@@ -859,16 +862,22 @@ enum TranscriptParagraphs {return cjk ? text.filter(\.isLetter).count >= full.cjk : text.split(whereSeparator: \.isWhitespace).count >= full.words}- static func group(_ lines: [TranscriptLine], _ speakers: [String: Int]) -> [[TranscriptLine]] {+ static func group(_ lines: [TranscriptLine], _ speakers: [String: Int], pending: Set<String> = []) -> [[TranscriptLine]] {var out: [[TranscriptLine]] = []var key: String?// Before any number is on show (two voices with five lines each), a question and its answer// would read as one block: a known voice that differs from the paragraph's starts a new one.- // Short lines are left out, as for numbers: their voice is too often wrong.+ // Short lines' voices are left out, as for numbers: they are too often wrong. A line with no+ // voice was like none heard so far (or too short to start one): next to a known voice that is+ // more often someone else ("Great." / "Let's lock that in" after the answer), so it counts as+ // a voice of its own (`noVoice`), which the paragraphs' voices then hold. One still being+ // heard (`pending`) stays put meanwhile rather than jump out and back.var voice: Int?+ let noVoice = -1for l in lines {let k = (l.speaker == "me" ? "me" : speakers[l.id].map { "n\($0)" } ?? "?") + (l.via ?? "")- let v = speakers.isEmpty && l.speaker == "them" && SpeakerLabels.substantive(l.src) ? l.voice : nil+ let heard = l.voice.map { SpeakerLabels.substantive(l.src) ? $0 : nil } ?? (pending.contains(l.id) ? nil : noVoice)+ let v = speakers.isEmpty && l.speaker == "them" ? heard : nilif k == key, let p = out.last, let first = p.first, l.t - first.t <= span, !isFull(p),voice == nil || v == nil || v == voice {out[out.count - 1].append(l)diff --git a/Sources/Cicada/NotesWindow.swift b/Sources/Cicada/NotesWindow.swiftindex 64b941c..0bd5ad7 100644--- a/Sources/Cicada/NotesWindow.swift+++ b/Sources/Cicada/NotesWindow.swift@@ -918,7 +918,7 @@ struct NotesWindowView: View {jumpTo: jumpTo, speakers: speakers, startedAt: store.liveStart,identifying: model.identifyingLanguage,voices: speakers.isEmpty ? [:] : SpeakerLabels.voiceNumbers(lines), marked: editingVoice,- places: RecordList.heardBoth(lines), settling: model.settling,+ places: RecordList.heardBoth(lines), settling: model.settling, voicePending: model.voicePending,onAssign: { ids, voice in if let s = session { model.assignLines(session: s.id, ids, to: voice) } },onRevert: { lineID, fix in if let s = session { model.fixes.revert(fix, lineID: lineID, in: s.id) } }) {LivePartialRow(model: model, startedAt: store.liveStart)diff --git a/Sources/Cicada/SpeakerID.swift b/Sources/Cicada/SpeakerID.swiftindex 96b7d72..8425dce 100644--- a/Sources/Cicada/SpeakerID.swift+++ b/Sources/Cicada/SpeakerID.swift@@ -301,9 +301,11 @@ final class SpeakerTagger {func merge(_ from: Int, into: Int) { queue.async { [self] in clusterer.merge(from, into: into) } }- func tag(lineID: String, samples: [Float]) {+ /// `done` once the line has its voice, or is known to have none.+ func tag(lineID: String, samples: [Float], done: @escaping @MainActor () -> Void = {}) {voice(of: samples) { [weak self] voice inif let voice { self?.onVoice?(lineID, voice) }+ done()}}diff --git a/Tests/CicadaTests/NotesWindowTests.swift b/Tests/CicadaTests/NotesWindowTests.swiftindex 97f43b4..85d411e 100644--- a/Tests/CicadaTests/NotesWindowTests.swift+++ b/Tests/CicadaTests/NotesWindowTests.swift@@ -53,13 +53,39 @@ import Testingfunc said(_ id: String, _ t: Double, _ voice: Int?, _ src: String = "three whole words") -> TranscriptLine {var l = line(id, t, "them", src); l.voice = voice; return l}- // A speaks, B asks, A answers; a line with no voice yet and a short "Yeah." heard as A stay put.+ // A speaks, B asks, A answers; a short "Yeah." heard as A stays put. b was like no voice,+ // and reads on its own.let lines = [said("a", 0, 1), said("b", 5, nil), said("c", 9, 2), said("d", 12, 1, "Yeah."),said("e", 14, 1), said("f", 18, 1)]- #expect(TranscriptParagraphs.group(lines, [:]).map { $0.map(\.id) } == [["a", "b"], ["c", "d"], ["e", "f"]])+ #expect(TranscriptParagraphs.group(lines, [:]).map { $0.map(\.id) } == [["a"], ["b"], ["c", "d"], ["e", "f"]])// Once numbers show, they decide: lines without one stay together as before.let shown = TranscriptParagraphs.group(lines, ["x": 1])#expect(shown.map { $0.map(\.id) } == [["a", "b", "c", "d", "e", "f"]])+ // A line whose voice is still being heard stays with the paragraph meanwhile.+ let waiting = [said("a", 0, 1), said("b", 3, 1), said("c", 6, nil)]+ #expect(TranscriptParagraphs.group(waiting, [:], pending: ["c"]).map { $0.map(\.id) } == [["a", "b", "c"]])+ #expect(TranscriptParagraphs.group(waiting, [:]).map { $0.map(\.id) } == [["a", "b"], ["c"]])+ }++ /// The sample meeting: "Great, let's lock that in." is too short to start a voice of its own+ /// and like no voice heard so far, so it has none. It doesn't join the answer before it.+ @Test func lineLikeNoVoiceStartsItsOwnParagraph() {+ func said(_ id: String, _ t: Double, _ voice: Int?, _ src: String) -> TranscriptLine {+ var l = line(id, t, "them", src); l.voice = voice; return l+ }+ let lines = [said("a", 0, 0, "Okay, so where are we on the launch?"),+ said("b", 2, 1, "Uh, I think we can ship March 3rd if design signs off by Friday."),+ said("c", 7, nil, "Great, let's lock that in."),+ said("d", 9, nil, "Then I'll tell the team today."),+ said("e", 12, 1, "Sounds good to me.")]+ #expect(TranscriptParagraphs.group(lines, [:]).map { $0.map(\.id) } == [["a"], ["b"], ["c", "d"], ["e"]])+ // The live recognizer gave "Great." a line of its own: too short to compare, but it has no+ // voice either, and starts the next speaker's paragraph.+ let short = [lines[1], said("g", 7, nil, "Great."), said("h", 8, nil, "Let's lock that in")]+ #expect(TranscriptParagraphs.group(short, [:]).map { $0.map(\.id) } == [["b"], ["g", "h"]])+ // Voices off: no line has one, and one person's lines still read as a paragraph.+ let off = lines.map { var l = $0; l.voice = nil; return l }+ #expect(TranscriptParagraphs.group(off, [:]).map(\.count) == [5])}@Test func joinSpacesWordsNotChinese() {