Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.
TypeScript ai-meeting-assistantai-notetakerelectrongranola-alternativelinuxllama-cpplocal-ailocal-firstmacosmcpmeeting-minutesmeeting-notesoffline-firstopen-sourceprivacyspeech-to-texttranscriptionwhisperwhisper-cppwindows
Prevent Zoom captions from becoming transcript speaker names
Eric Brownroutfcb97915e744
diff --git a/app/src/main/asr/pipeline.ts b/app/src/main/asr/pipeline.tsindex af0642a9..a03a4cc8 100644--- a/app/src/main/asr/pipeline.ts+++ b/app/src/main/asr/pipeline.ts@@ -1,3 +1,4 @@+import { segmentSpeaker } from '../speakerName'import type { Segment } from '../store'import type { Track, TranscribeWarn } from '../capture'import type { TranscriptPartial } from '../../shared/types'@@ -108,7 +109,7 @@ export function createPipeline(p: {const spell = (t: string) => { try { return p.respell?.(t) ?? t } catch { return t } }// the mic is always the person using Yogurt- const speakerOf = (l: Line) => { if (l.track === 'me') return 'me'; try { return p.nameOf?.(l.startMs, l.endMs) ?? null } catch { return null } }+ const speakerOf = (l: Line) => { if (l.track === 'me') return 'me'; try { return segmentSpeaker(p.nameOf?.(l.startMs, l.endMs)) } catch { return null } }const out = (l: Line, hidden = false): Out => ({ meetingId: p.meetingId, track: l.track, startMs: l.startMs, endMs: l.endMs, text: spell(l.text), speaker: speakerOf(l), ...(hidden ? { hidden: true } : {}) })const give = (lines: Line[]) => {if (!lines.length) returndiff --git a/app/src/main/backup.ts b/app/src/main/backup.tsindex b2e3ad54..c12ab2e4 100644--- a/app/src/main/backup.ts+++ b/app/src/main/backup.ts@@ -1,3 +1,5 @@+import { readDraftLines } from './store'+import { segmentSpeaker } from './speakerName'import { migrateMeetingChats } from './library/store'import backupFormat from '../shared/backupFormat.json'import { backfillPeople, mergePeople } from './people'@@ -107,7 +109,8 @@ export function mergeBackup(into: DatabaseSync, from: DatabaseSync): { added: stfor (const row of p.read.all(id) as Row[]) {// a meeting that was recording when the backup was made stopped there, as after a crashif (p.table === 'meetings' && row.state === 'recording') row.state = 'stopped'- if (p.table === 'segments' && lettered && row.track === 'them') row.speaker = null+ if (p.table === 'segments') row.speaker = lettered && row.track === 'them' ? null : segmentSpeaker(row.speaker)+ if (p.table === 'transcription_drafts') row.payload = JSON.stringify(readDraftLines(row.payload))const r = p.write.run(...p.cols.map((c) => row[c]))// the insert trigger puts every line in search; hidden echo lines come out again, as addSegments doesif (p.table === 'segments') {diff --git a/app/src/main/callNames/parse.ts b/app/src/main/callNames/parse.tsindex 1472157f..190ec978 100644--- a/app/src/main/callNames/parse.ts+++ b/app/src/main/callNames/parse.ts@@ -1,3 +1,5 @@+import { speakerName } from '../speakerName'+/*** What a call app's window says about who is in the call and who is talking, read from its accessibility tree* (yogurt-mac call-watch copies it out on a Mac, yogurt-system on Linux; this reads either). Every rule fails towards@@ -69,7 +71,7 @@ const tagsOf = (raw: string): string[] => {const cleanZoom = (raw: string): string | null => {let name = raw.normalize('NFKC').trim()while (ZOOM_TAGS.test(name)) name = name.replace(ZOOM_TAGS, '')- return name && !/^participants \(/i.test(name) ? name : null+ return /^participants \(/i.test(name) ? null : speakerName(name)}/** "Ana Ruiz, Computer audio unmuted, Video off, Active speaker" → Ana Ruiz, talking; null when it isn't a tile */@@ -100,9 +102,12 @@ export function zoomLinuxTile(name: string): { name: string; talking: boolean }if (!m) return nullconst talking = LINUX_ACTIVE.test(m[1])const person = cleanZoom(m[1].replace(LINUX_ACTIVE, ''))- return person && person.length <= 60 ? { name: person, talking } : null+ return person ? { name: person, talking } : null}+const zoomCaption = (n: AxNode) => n.r === 'caption' || /caption|transcript/i.test(n.i ?? '')+ || /^(?:(?:closed|live|full) )?(?:captions?|transcript(?:ion)?)$/i.test(n.d ?? n.t ?? '')+function readZoom(windows: AxWindow[]): CallReading {const speaking: string[] = [], participants: string[] = []const linuxTiles: Array<{ name: string; talking: boolean }> = []@@ -127,7 +132,10 @@ function readZoom(windows: AxWindow[]): CallReading {for (const raw of [n.v, n.t]) {if (!raw) continueconst v = raw.normalize('NFKC')- for (const key of TALKING) if (v.startsWith(key)) { const name = cleanZoom(v.slice(key.length).replace(/^\s*[::]\s*/, '')); if (name) speaking.push(name) }+ const colon = v.indexOf(':')+ if (colon < 0 || !TALKING.includes(v.slice(0, colon).trimEnd()) || zoomCaption(n) || up.some(zoomCaption)) continue+ const name = cleanZoom(v.slice(colon + 1))+ if (name) speaking.push(name)}}// a row of the participants list: its first text is the name, "(me)" on the person using Yogurtdiff --git a/app/src/main/speakerName.ts b/app/src/main/speakerName.tsnew file mode 100644index 00000000..dd3bc0f9--- /dev/null+++ b/app/src/main/speakerName.ts@@ -0,0 +1,20 @@+import { AUDIO_SPEAKER } from '../shared/audioUpload'++const ABBREVIATION = /^(?:(?:\p{L}\.)+|(?:Dr|Prof|Mr|Mrs|Ms|Jr|Sr|St)\.),?$/iu++/** Call apps expose captions alongside names. Keep initials, suffixes and dotted usernames. */+export function speakerName(value: unknown): string | null {+ if (typeof value !== 'string') return null+ const name = value.trim()+ if (name.length > 60 || !/\p{L}/u.test(name) || /[\p{Cc}\p{Zl}\p{Zp}]/u.test(name)) return null+ const words = name.normalize('NFKC').split(/\s+/)+ if (words.length > 6) return null+ for (const word of words) {+ if (ABBREVIATION.test(word)) continue+ const withoutInnerDots = word.replace(/(?<=[\p{L}\p{N}])\.(?=[\p{L}\p{N}])/gu, '')+ if (/[\p{Sentence_Terminal}:;؛]/u.test(withoutInnerDots)) return null+ }+ return name+}++export const segmentSpeaker = (value: unknown) => value === AUDIO_SPEAKER ? AUDIO_SPEAKER : speakerName(value)diff --git a/app/src/main/store.ts b/app/src/main/store.tsindex ac41914c..76164005 100644--- a/app/src/main/store.ts+++ b/app/src/main/store.ts@@ -1,3 +1,4 @@+import { segmentSpeaker, speakerName } from './speakerName'import type { TranscriptionState } from '../shared/transcription'import { eventIds, type CalEvent } from './calendar'import { matchSearchPeople, searchPersonKey, uniqueSearchPeople } from '../shared/searchPeople'@@ -76,9 +77,12 @@ const toMeeting = (r: Row): Meeting => ({...(r.duration_ms == null ? {} : { durationMs: Number(r.duration_ms) }),...(r.trashed_at == null ? {} : { trashedAt: Number(r.trashed_at) }),})+const draftLine = (s: Omit<Segment, 'id'>) => ({ ...s, speaker: segmentSpeaker(s.speaker) })+export const readDraftLines = (payload: unknown): Omit<Segment, 'id'>[] => JSON.parse(String(payload)).map(draftLine)+const toSegment = (r: Row): Segment => ({id: Number(r.id), meetingId: String(r.meeting_id), track: r.track as Segment['track'], startMs: Number(r.start_ms), endMs: Number(r.end_ms),- text: String(r.text), speaker: r.speaker == null ? null : String(r.speaker), hidden: Number(r.hidden ?? 0) === 1,+ text: String(r.text), speaker: segmentSpeaker(r.speaker), hidden: Number(r.hidden ?? 0) === 1,...(Number(r.echo_confident ?? 0) === 1 ? { echoConfident: true } : {}),})@@ -502,10 +506,10 @@ export class Store {} catch(error) {this.db.exec('ROLLBACK');throw error}}transcriptionDraft(id: string): Omit<Segment,'id'>[] {- return this.db.prepare('SELECT payload FROM transcription_drafts WHERE meeting_id = ? ORDER BY rowid').all(id).flatMap(row => JSON.parse(String(row.payload)))+ return this.db.prepare('SELECT payload FROM transcription_drafts WHERE meeting_id = ? ORDER BY rowid').all(id).flatMap(row => readDraftLines(row.payload))}addTranscriptionDraft(id: string, segments: Omit<Segment,'id'>[]) {- this.db.prepare('INSERT INTO transcription_drafts (meeting_id,payload) VALUES (?,?)').run(id,JSON.stringify(segments))+ this.db.prepare('INSERT INTO transcription_drafts (meeting_id,payload) VALUES (?,?)').run(id,JSON.stringify(segments.map(draftLine)))}clearTranscriptionDraft(id: string) { this.db.prepare('DELETE FROM transcription_drafts WHERE meeting_id = ?').run(id) }commitTranscriptionDraft(id: string) {@@ -530,7 +534,7 @@ export class Store {this.db.exec('BEGIN')try {for (const s of segs) {- const r = ins.run(s.meetingId, s.track, s.startMs, s.endMs, s.text, s.speaker, s.hidden ? 1 : 0, s.hidden && s.echoConfident ? 1 : 0)+ const r = ins.run(s.meetingId, s.track, s.startMs, s.endMs, s.text, segmentSpeaker(s.speaker), s.hidden ? 1 : 0, s.hidden && s.echoConfident ? 1 : 0)// a hidden line is not for searchif (s.hidden) this.db.prepare("INSERT INTO segments_fts(segments_fts, rowid, text) VALUES ('delete', ?, ?)").run(r.lastInsertRowid, s.text)}@@ -552,7 +556,7 @@ export class Store {const names = arriving && previous.length ? [arriving] : (this.db.prepare("SELECT speaker FROM segments WHERE meeting_id = ? AND track = 'them' AND speaker IS NOT NULL GROUP BY speaker ORDER BY MIN(start_ms), MIN(id)").all(meetingId) as Row[]).map(r => String(r.speaker))- const next = speakerOrder(previous, [...names, arriving ?? null])+ const next = speakerOrder(previous, [...names, arriving].map(speakerName))if (next.length !== previous.length) {try { this.db.prepare('UPDATE meetings SET speaker_order = ? WHERE id = ?').run(JSON.stringify(next), meetingId) }catch (e) { console.warn('Could not save speaker colour order', e); return previous }@@ -610,7 +614,7 @@ export class Store {const up = this.db.prepare('UPDATE segments SET speaker = ? WHERE id = ?')this.db.exec('BEGIN')try {- for (const s of list) up.run(s.speaker, s.id)+ for (const s of list) up.run(segmentSpeaker(s.speaker), s.id)this.db.exec('COMMIT')} catch (e) { this.db.exec('ROLLBACK'); throw e }}diff --git a/app/test/backup.test.ts b/app/test/backup.test.tsindex d6d5e879..5c0bbbc0 100644--- a/app/test/backup.test.ts+++ b/app/test/backup.test.ts@@ -63,6 +63,19 @@ describe('backup merge', () => {mergeBackup(into.db, from.db)expect(into.segments(m.id).map((s) => s.speaker)).toEqual([null])})+ it('restores the words of a legacy segment and draft with an invalid speaker', () => {+ const from = openStore(':memory:'), into = openStore(':memory:')+ stores.push(from, into)+ const m = fill(from, 'Old', 'pricing')+ const [line] = from.segments(m.id)+ from.db.prepare('UPDATE segments SET speaker = ? WHERE id = ?').run('Is it ready?', line.id)+ from.db.prepare('INSERT INTO transcription_drafts (meeting_id, payload) VALUES (?, ?)')+ .run(m.id, JSON.stringify([{ ...line, speaker: 'Is it ready?' }]))+ mergeBackup(into.db, from.db)+ expect(into.db.prepare('SELECT speaker, text FROM segments WHERE hidden = 0').get()).toMatchObject({ speaker: null, text: line.text })+ const payload = into.db.prepare('SELECT payload FROM transcription_drafts').get()?.payload+ expect(JSON.parse(String(payload))[0]).toMatchObject({ speaker: null, text: line.text })+ })it('adds meetings that are not here with every row that belongs to them, and skips the ones that are', () => {const from = fresh(), into = fresh()const shared = fill(from, 'Weekly sync', 'budget')diff --git a/app/test/callParse.test.ts b/app/test/callParse.test.tsindex 3a1779d2..f60b5497 100644--- a/app/test/callParse.test.ts+++ b/app/test/callParse.test.ts@@ -49,6 +49,23 @@ describe('Zoom', () => {expect(r.speaking).toEqual(['Dana Smith'])})+ it.each([+ 'Talking points',+ // The native accessibility reader clips a text value at 300 characters, even mid-word.+ ('Talking: ' + 'The draft has a section we still need to revise before the review. '.repeat(5)).slice(0, 300),+ 'Talking: Ready?',+ ])('leaves a line unnamed when Zoom exposes speech as static text (%#)', (v) => {+ const snapshot = zoomWindow([], [], [node('AXStaticText', { v })])+ const reading = readCall('zoom', [snapshot])+ expect(nameFor({ startMs: 0, endMs: 800 }, [{ ms: 0, ...reading }])).toBeNull()+ })++ it.each([{ i: 'captions' }, { d: 'Live Transcript' }])('ignores caption text beside a localized speaker label (%#)', (panel) => {+ const captions = node('AXGroup', panel, node('AXStaticText', { v: 'Talking: First Draft' }))+ const label = node('AXStaticText', { v: '正在发言:李明' })+ expect(readCall('zoom', [zoomWindow([], [], [captions, label])]).speaking).toEqual(['李明'])+ })+it('a Zoom that changed its window reads as nothing, never a wrong name', () => {const r = readCall('zoom', [win(node('AXWindow', {}, node('AXGroup', { d: 'Dana Smith' }), node('AXTabGroup', { d: 'Chat' }), node('AXStaticText', { v: 'Dana Smith' })))])expect(r).toEqual({ speaking: [], participants: [], me: null })diff --git a/app/test/pipeline.test.ts b/app/test/pipeline.test.tsindex ff3ed224..aca43985 100644--- a/app/test/pipeline.test.ts+++ b/app/test/pipeline.test.ts@@ -63,6 +63,14 @@ describe('pipeline', () => {expect(s.sent.sort()).toEqual(['I will send the notes', 'Thanks for the update'])})+ it('leaves a live line unnamed when attribution returns speech', async () => {+ const s = setup(() => [], { nameOf: () => 'Is everyone ready?' })+ s.p.speechLines('them', [{ track: 'them', startMs: 0, endMs: 800, text: 'Keep these words' }])+ await s.p.finish()+ expect(s.saved).toMatchObject([{ speaker: null, text: 'Keep these words' }])+ expect(s.sent).toEqual(['Keep these words'])+ })+it('a line of the other side gets the name the call app showed for its time; the mic is always the person', async () => {const asked: Array<[number, number]> = []const s = setup((c) => [line(c, c.track === 'me' ? 'mine' : 'theirs')], { nameOf: (a, b) => { asked.push([a, b]); return 'Dana Smith' } })diff --git a/app/test/store.test.ts b/app/test/store.test.tsindex c6b5dfce..be6238fd 100644--- a/app/test/store.test.ts+++ b/app/test/store.test.ts@@ -3,6 +3,9 @@ import { mkdtempSync, rmSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { DatabaseSync } from 'node:sqlite'+import { AUDIO_SPEAKER } from '../src/shared/audioUpload'+import { transcriptSpeaker } from '../src/shared/transcript'+import { previousSpeaker } from '../src/shared/transcriptReplacement'import { openStore, type Store } from '../src/main/store'const dirs: string[] = []@@ -68,6 +71,50 @@ describe('store', () => {expect(s.segments(m.id).map((x) => x.speaker)).toEqual(['Dana Smith', null])})+ it('saves plausible names and leaves speech unnamed on insert and late attribution', () => {+ const s = openStore(':memory:')+ stores.push(s)+ const meetingId = s.createMeeting({ ...base, startedAt: 1 }).id+ const line = { meetingId, track: 'them' as const, startMs: 0, endMs: 1, text: 'Keep these words' }+ const valid = ['李明', 'Ana María de la Cruz', 'J. R. Smith Jr.', 'Smith, Dana', 'Mary-Jane O’Neil', 'alex.lee', 'A'.repeat(60), AUDIO_SPEAKER]+ const invalid = ['A'.repeat(61), 'we can go over this next week', 'All done.', 'Ready?', '可以。', 'Wait…', 'Try: again', 'Two\nlines']+ s.addSegments([...valid, ...invalid].map(speaker => ({ ...line, speaker })))+ const saved = () => s.db.prepare('SELECT speaker FROM segments ORDER BY id').all().map(row => row.speaker)+ expect(saved()).toEqual([...valid, ...invalid.map(() => null)])+ s.setSegmentSpeakers([{ id: s.segments(meetingId)[0].id, speaker: 'Any questions?' }])+ expect(saved()[0]).toBeNull()+ })++ it('reads legacy speech labels as Them without editing the saved words or label', () => {+ const s = openStore(':memory:')+ stores.push(s)+ const meetingId = s.createMeeting({ ...base, startedAt: 1 }).id+ const line = { meetingId, track: 'them' as const, startMs: 0, endMs: 800, text: 'Keep these words', speaker: 'Ready?' }+ s.db.prepare('INSERT INTO segments (meeting_id, track, start_ms, end_ms, text, speaker) VALUES (?, ?, ?, ?, ?, ?)')+ .run(meetingId, line.track, line.startMs, line.endMs, line.text, line.speaker)+ s.addSegments([{ ...line, startMs: 800, endMs: 1600, speaker: 'Dana Smith' }])+ const saved = s.segments(meetingId)+ expect(saved[0]).toMatchObject({ speaker: null, text: line.text })+ expect(saved.map(transcriptSpeaker)).toEqual(['Them', 'Dana Smith'])+ expect(previousSpeaker(saved, 'them', 0, 800)).toBeNull()+ expect(s.speakerOrder(meetingId)).toEqual(['Dana Smith'])+ expect(s.db.prepare('SELECT speaker FROM segments WHERE id = ?').get(saved[0].id)?.speaker).toBe(line.speaker)+ })++ it('validates draft speakers on save and when committing a legacy draft', () => {+ const s = openStore(':memory:')+ stores.push(s)+ const meetingId = s.createMeeting({ ...base, startedAt: 1 }).id+ const line = { meetingId, track: 'them' as const, startMs: 0, endMs: 800, text: 'Keep these words', speaker: 'Ready?' }+ s.addTranscriptionDraft(meetingId, [line])+ const payload = s.db.prepare('SELECT payload FROM transcription_drafts').get()?.payload+ expect(JSON.parse(String(payload))).toEqual([{ ...line, speaker: null }])+ s.db.prepare('UPDATE transcription_drafts SET payload = ?').run(JSON.stringify([line]))+ expect(s.transcriptionDraft(meetingId)).toEqual([{ ...line, speaker: null }])+ s.commitTranscriptionDraft(meetingId)+ expect(s.db.prepare('SELECT speaker, text FROM segments').get()).toMatchObject({ speaker: null, text: line.text })+ })+it('deleteMeeting removes the meeting with its lines, notes and chat, and search no longer finds it', () => {const s = fresh()const m = s.createMeeting({ ...base, title: 'Budget review', startedAt: 1, state: 'done' })