知了 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: speaker names from your AI service are still found when the reply comes wrapped in a code block
wqugurub9aa1d0f37da
diff --git a/Sources/Cicada/SpeakerID.swift b/Sources/Cicada/SpeakerID.swiftindex 140f093..92f5a79 100644--- a/Sources/Cicada/SpeakerID.swift+++ b/Sources/Cicada/SpeakerID.swift@@ -365,7 +365,10 @@ enum SpeakerNameGuess {/// `refuted`: voices Ling named on a line they neither said nor spoke next to ("I'm Christina"/// in an advert, given to the anchor); such a name is dropped, and an earlier copy of it too.static func read(_ reply: String, _ s: Session) -> (found: [Int: VoiceGuess], refuted: [Int: String]) {- guard let data = reply.data(using: .utf8),+ // The object alone: a reply asked again without JSON mode may come in a fence.+ var text = reply+ if let a = text.firstIndex(of: "{"), let b = text.lastIndex(of: "}"), a < b { text = String(text[a...b]) }+ guard let data = text.data(using: .utf8),let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],let list = obj["speakers"] as? [[String: Any]] else { return ([:], [:]) }let voiceOf = Dictionary(uniqueKeysWithValues: SpeakerLabels.voiceNumbers(s.lines).map { ($1, $0) })diff --git a/Tests/CicadaTests/SpeakerTests.swift b/Tests/CicadaTests/SpeakerTests.swiftindex fb37d58..19f64c2 100644--- a/Tests/CicadaTests/SpeakerTests.swift+++ b/Tests/CicadaTests/SpeakerTests.swift@@ -141,6 +141,8 @@ import Testing#expect(r.found.keys.sorted() == [0] && r.found[0]?.name == "Amos Hochstein")#expect(r.found[0]?.evidence.hasPrefix("00:11 “Okay, Amos") == true)#expect(r.refuted == [1: "Christina Raffini"])+ // Asked again without JSON mode, the same reply may come in a fence.+ #expect(SpeakerNameGuess.read("```json\n" + reply + "\n```", s).found[0]?.name == "Amos Hochstein")// Said by the speaker themselves; "L12, L13" reads as L12; no evidence, or one out of range, is no name.#expect(SpeakerNameGuess.parse(#"{"speakers": [{"speaker": 2, "name": "Anchor", "evidence": "L12, L14"}]}"#, s)[1]?.name == "Anchor")#expect(SpeakerNameGuess.parse(#"{"speakers": [{"speaker": 2, "name": "Anchor"}]}"#, s).isEmpty)