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
Transcript: take off meeting names whisper reads back from its prompt as a speaker label
christianmata773cc2e0953
diff --git a/app/src/main/asr/hallucination.ts b/app/src/main/asr/hallucination.tsindex 318a1cba..ea20edb8 100644--- a/app/src/main/asr/hallucination.ts+++ b/app/src/main/asr/hallucination.ts@@ -37,3 +37,16 @@ const GUESSES = new Set([/** One of whisper's stock lines for silence. Only dropped where the audio was not clearly speech: people do say thank you. */export const isSilenceGuess = (text: string): boolean => GUESSES.has(tokens(text).join(' '))++/**+ * Whisper sometimes reads names from its prompt back as a speaker label before real speech ("Eric and Sam Lee: so let+ * me just get"). The label goes when it is the prompt word for word; a colon after words of its own stays.+ */+export function withoutPromptLabel(text: string, prompt: string): string {+ const m = /^([^:\n]{1,120}):\s+(\S[\s\S]*)$/.exec(text)+ if (!m) return text+ const label = tokens(m[1]), p = tokens(prompt)+ if (!label.length || !p.length) return text+ const inPrompt = p.some((_, i) => label.every((w, k) => p[i + k] === w))+ return inPrompt ? m[2] : text+}diff --git a/app/src/main/asr/transcribe.ts b/app/src/main/asr/transcribe.tsindex 1a373da1..7be1026f 100644--- a/app/src/main/asr/transcribe.ts+++ b/app/src/main/asr/transcribe.ts@@ -3,7 +3,7 @@ import type { Track } from '../capture'import type { Chunk } from './chunker'import { languageName } from './appleSpeech'import { tokens } from './echo'-import { isPromptEcho, isSilenceGuess } from './hallucination'+import { isPromptEcho, isSilenceGuess, withoutPromptLabel } from './hallucination'/** What a chunk turns into: lines on meeting time. The meeting and the speaker are added where they are saved. */export type Line = Omit<Segment, 'id' | 'meetingId' | 'speaker'> & {@@ -104,12 +104,16 @@ export function createTranscriber(o: Opts): Transcribe {const body = (await res.json()) as Verboseconst lines: Line[] = []for (const s of body.segments ?? []) {- const text = s.text.replace(/\s+/g, ' ').trim()+ const said = s.text.replace(/\s+/g, ' ').trim()+ // names from the prompt read back as a speaker label ("Eric and Sam Lee: so..."): the speech after it stays+ const text = withoutPromptLabel(said, prompt)if (!text || NOISE.test(text)) continueif ((s.no_speech_prob ?? 0) > 0.6 && (s.avg_logprob ?? 0) < -1) continue// read back from the prompt, or a stock line over a faint sound: whisper had nothing to readif (isPromptEcho(text, prompt) || (faint && isSilenceGuess(text))) continue- const words = s.words?.map((w) => ({ text: w.word, startMs: Math.round(c.startMs + w.start * 1000), endMs: Math.round(c.startMs + w.end * 1000) }))+ // the label's words (through the one carrying its colon) go with it+ const kept = text === said ? s.words : s.words?.slice((s.words.findIndex((w) => w.word.includes(':')) + 1) || 0)+ const words = kept?.map((w) => ({ text: w.word, startMs: Math.round(c.startMs + w.start * 1000), endMs: Math.round(c.startMs + w.end * 1000) }))lines.push({ track: c.track, startMs: Math.round(c.startMs + s.start * 1000), endMs: Math.round(c.startMs + s.end * 1000), text, ...(words?.length ? { words } : {}) })}return { lines, text: lines.map((l) => l.text).join(' '), language: body.detected_language ?? body.language ?? 'auto', prob: body.detected_language_probability ?? 0 }diff --git a/app/test/hallucination.test.ts b/app/test/hallucination.test.tsindex cac3b034..4d2592b8 100644--- a/app/test/hallucination.test.ts+++ b/app/test/hallucination.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { isPromptEcho, isSilenceGuess } from '../src/main/asr/hallucination'+import { isPromptEcho, isSilenceGuess, withoutPromptLabel } from '../src/main/asr/hallucination'describe('prompt echo', () => {const prompt = 'Northwind sync. With Sam Lee of Northwind and Joe Park of Acme.'@@ -40,3 +40,20 @@ describe('silence guesses', () => {for (const t of ['Thank you for the update on the budget.', 'You said Tuesday.', 'Bye for now, see you Monday.']) expect(isSilenceGuess(t)).toBe(false)})})++describe('the prompt read back as a speaker label', () => {+ const prompt = 'Product board. With Eric and Christian Mathiesen.'+ it('takes off names from the prompt that whisper put before real speech as a label', () => {+ expect(withoutPromptLabel('Eric and Christian Mathiesen: So let me just get', prompt)).toBe('So let me just get')+ expect(withoutPromptLabel('With Eric and Christian Mathiesen: Hurt to summarize the product board.', prompt)).toBe('Hurt to summarize the product board.')+ expect(withoutPromptLabel('Christian Mathiesen: okay', prompt)).toBe('okay')+ expect(withoutPromptLabel('Eric: yeah, let me check', prompt)).toBe('yeah, let me check')+ })+ it('leaves speech alone: a colon that follows words of its own, or names nobody gave it', () => {+ expect(withoutPromptLabel('Here is the plan: ship Friday', prompt)).toBe('Here is the plan: ship Friday')+ expect(withoutPromptLabel('Note: the product board is late', prompt)).toBe('Note: the product board is late')+ expect(withoutPromptLabel('Eric and Christian Mathiesen joined late', prompt)).toBe('Eric and Christian Mathiesen joined late')+ expect(withoutPromptLabel('Eric and Christian Mathiesen:', prompt)).toBe('Eric and Christian Mathiesen:')+ expect(withoutPromptLabel('Eric: hi', '')).toBe('Eric: hi')+ })+})diff --git a/app/test/transcribe.test.ts b/app/test/transcribe.test.tsindex 55e9c347..789824c9 100644--- a/app/test/transcribe.test.ts+++ b/app/test/transcribe.test.ts@@ -79,6 +79,15 @@ describe('transcribe', () => {const tr = createTranscriber({ url: async () => s.url, prompt: () => 'With Alex Morgan of Zentrik.' })expect((await tr(chunk('them', 0))).map((l) => l.text)).toEqual(['Shall we start with the roadmap?'])})+ it('takes off prompt names read back as a speaker label, with their words, and keeps the speech', async () => {+ const s = await stub([{ segments: [{ start: 0, end: 2, text: ' Alex Morgan: Shall we start?', words: [+ { word: ' Alex', start: 0, end: 0.2 }, { word: ' Morgan:', start: 0.2, end: 0.4 }, { word: ' Shall', start: 0.5, end: 0.8 }, { word: ' we', start: 0.8, end: 1 }, { word: ' start?', start: 1, end: 1.4 },+ ] }] }])+ const tr = createTranscriber({ url: async () => s.url, prompt: () => 'With Alex Morgan of Zentrik.' })+ const [line] = await tr(chunk('them', 0))+ expect(line.text).toBe('Shall we start?')+ expect(line.words?.map((w) => w.text.trim())).toEqual(['Shall', 'we', 'start?'])+ })it('drops a stock silence line from a chunk that was not clearly speech, but keeps a real one', async () => {const s = await stub([say('Thank you.')])const tr = createTranscriber({ url: async () => s.url })