Fix Meet visual: reject solid avatar tiles + screen-share OCR
Root cause of the "4 people → 2 speakers" Meet call: the colored-border detector
read solid camera-off avatar tiles (orange "J", magenta "G") as active speakers
for the ENTIRE call. Those whole-call phantom spans dominated backend name
attribution, collapsing every remote voice onto one name — and the giant filled
bbox also swallowed screen-share text (WERUNBTC.COM ×49) as a speaker.
Validated against 9 real fixtures (harness over the real MeetAdapter):
Detection:
- FrameSampler.thinColoredPoints: coloured counterpart of thinWhitePoints — keeps
thin border/ring/pill edges, drops solid colour fills.
- GridCallAnalyzer.isHollow: reject a highlight component whose interior is filled
(a solid tile) vs a hollow ring (a real border). Config.maxInteriorFill (0.2 default).
- MeetAdapter: detect thin BLUE edges only (hue 180–240°, measured from the
fixtures), maxInteriorFill 0.3 (real Meet rings ≈0.2–0.3, solid tiles ≈0.36).
- Result on fixtures: John Arnold/Grant Gilliam (solid tiles) now NEVER detected;
Matt Odell/Mark detected when their blue cue is present. Sparse but never wrong —
correct for a naming hint over audio diarization.
OCR name hygiene:
- isLikelyName rejects domain-like screen-share text ("WERUNBTC.COM", OCR'd ".GOM").
- cleaned() strips trailing punctuation ("Mark." → "Mark").
- TimelineBuilder.canonicalizeByFrequency folds rare OCR misspellings into a
dominant near-twin name ("Matt Odel"/"MattOdell" → "Matt Odell", "Mare" → "Mark").
Tests: hollow-ring, extended OCR filter, fuzzy-merge. 65 pass.
This commit is contained in:
@@ -93,9 +93,57 @@ final class TimelineBuilder {
|
||||
closeSegment(name: name, state: st)
|
||||
states[name]?.open = false
|
||||
}
|
||||
segments = Self.canonicalizeByFrequency(segments)
|
||||
segments.sort { $0.start < $1.start }
|
||||
}
|
||||
|
||||
/// Fold rare OCR misspellings into the dominant name they're a typo of: a name with
|
||||
/// little total time is remapped to a much longer-running name with the same initial
|
||||
/// within a small edit distance (e.g. "Matt Odel"/"MattOdell"/"Mare" → "Matt Odell"/
|
||||
/// "Mark"). Conservative by design — it won't merge two well-attested speakers, only
|
||||
/// a transient variant into its clearly-dominant canonical. Pure/testable.
|
||||
static func canonicalizeByFrequency(_ segs: [VisualTimeline.Segment],
|
||||
minorMaxSec: Double = 5, dominanceRatio: Double = 8,
|
||||
maxEdits: Int = 2) -> [VisualTimeline.Segment] {
|
||||
var dur: [String: Double] = [:]
|
||||
for s in segs { dur[s.name, default: 0] += s.end - s.start }
|
||||
let names = Array(dur.keys)
|
||||
var remap: [String: String] = [:]
|
||||
for minor in names {
|
||||
let md = dur[minor]!
|
||||
guard md <= minorMaxSec, let mInit = minor.first else { continue }
|
||||
var best: String?, bestDur = 0.0
|
||||
for major in names where major != minor {
|
||||
let Md = dur[major]!
|
||||
guard Md >= md * dominanceRatio, Md > bestDur, major.first == mInit else { continue }
|
||||
if levenshtein(minor.lowercased(), major.lowercased()) <= maxEdits { best = major; bestDur = Md }
|
||||
}
|
||||
if let b = best { remap[minor] = b }
|
||||
}
|
||||
guard !remap.isEmpty else { return segs }
|
||||
return segs.map { s in
|
||||
remap[s.name].map { VisualTimeline.Segment(start: s.start, end: s.end, name: $0,
|
||||
confidence: s.confidence, source: s.source) } ?? s
|
||||
}
|
||||
}
|
||||
|
||||
/// Levenshtein edit distance (small strings — names).
|
||||
static func levenshtein(_ a: String, _ b: String) -> Int {
|
||||
let x = Array(a), y = Array(b)
|
||||
if x.isEmpty { return y.count }; if y.isEmpty { return x.count }
|
||||
var prev = Array(0...y.count)
|
||||
var cur = [Int](repeating: 0, count: y.count + 1)
|
||||
for i in 1...x.count {
|
||||
cur[0] = i
|
||||
for j in 1...y.count {
|
||||
cur[j] = x[i-1] == y[j-1] ? prev[j-1]
|
||||
: Swift.min(prev[j-1], prev[j], cur[j-1]) + 1
|
||||
}
|
||||
swap(&prev, &cur)
|
||||
}
|
||||
return prev[y.count]
|
||||
}
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
private struct NameState {
|
||||
|
||||
Reference in New Issue
Block a user