Skip to content

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.

Recording pill: the wave moves when someone talks, not with the room; it opens 10 dB over the mic's own noise floor instead of a fixed level a laptop mic can sit at

Eric Brownroute3d87055161a
diff --git a/app/src/main/widget.ts b/app/src/main/widget.ts
index 37dbb2ea..3ff46ecd 100644
--- a/app/src/main/widget.ts
+++ b/app/src/main/widget.ts
@@ -1,4 +1,4 @@
-import { silentSpeech, speechSample } from '../shared/speechWave'
+import { micFloor, silentSpeech, speechSample } from '../shared/speechWave'
import { BrowserWindow, ipcMain, Notification, screen } from 'electron'
import { join } from 'node:path'
import type { Meeting } from './store'
@@ -63,6 +63,7 @@ export function createWidget(d: { open(meetingId: string): void; stop(meetingId:
platform?: NodeJS.Platform }) {
const model = new WidgetModel(d.os)
let speech = silentSpeech
+ let micLevels: number[] = []
let win: BrowserWindow | undefined
/**
* Linux (X11): Electron crashes when a window is destroyed while the X server still answers about its size, as
@@ -160,6 +161,7 @@ export function createWidget(d: { open(meetingId: string): void; stop(meetingId:
onMeetingStart((m) => {
speech = silentSpeech
+ micLevels = []
notifyOnChange = false; notice = null; stopPressed = false
model.start({ id: m.id, title: m.title, startedAt: m.resume ? m.resume.startedAt - m.resume.capturedMs : m.startedAt })
open(); push()
@@ -198,7 +200,7 @@ export function createWidget(d: { open(meetingId: string): void; stop(meetingId:
onRecordingEvent((e) => {
if (!model.meetingId) return
if (e.t === 'level') {
- speech = speechSample(speech, e, performance.timeOrigin + performance.now())
+ speech = speechSample(speech, e, performance.timeOrigin + performance.now(), micFloor(micLevels, e))
broadcast('widget:level', { me: e.me, them: e.them, speech })
} else if (e.t === 'paused' && e.meetingId === model.meetingId) { model.pause(e.paused, e.at); push() }
else if (e.t === 'warn') { model.warn(e.code); push() }
diff --git a/app/src/shared/speechWave.ts b/app/src/shared/speechWave.ts
index 81fb1443..4180e6ce 100644
--- a/app/src/shared/speechWave.ts
+++ b/app/src/shared/speechWave.ts
@@ -17,10 +17,24 @@ export function speechAt(anchor: SpeechAnchor, now: number) {
return { drive, phase: anchor.phase + rise + fall }
}
-export function speechSample(previous: SpeechAnchor, input: { me: number; them: number }, now: number): SpeechAnchor {
- const db = Number.isFinite(input.me) ? input.me * 60 - 60 : -Infinity
+const micDb = (me: number) => Number.isFinite(me) ? me * 60 - 60 : -Infinity
+
+/**
+ * The mic's noise floor: its quietest tenth over the last minute of level packets (10 a second), as the transcriber
+ * measures it (asr/chunker.ts). A laptop mic in a quiet room can sit at -44 dB, where a fixed gate stays open for the
+ * whole call. Until five seconds have come in there is no floor and only the fixed levels apply.
+ */
+export function micFloor(recent: number[], input: { me: number }) {
+ recent.push(micDb(input.me))
+ if (recent.length > 600) recent.shift()
+ return recent.length < 50 ? -Infinity : [...recent].sort((a, b) => a - b)[Math.floor(recent.length / 10)]
+}
+
+/** Someone is talking at 10 dB over the floor (about 3x its loudness), and keeps talking down to 6 dB over it. */
+export function speechSample(previous: SpeechAnchor, input: { me: number; them: number }, now: number, floor = -Infinity): SpeechAnchor {
+ const db = micDb(input.me)
const held = previous.speaking && now - previous.at <= SPEECH_PACKET_TIMEOUT
- return { ...speechAt(previous, now), at: now, speaking: db >= -44.4 || (held && db > -49.2) }
+ return { ...speechAt(previous, now), at: now, speaking: db >= Math.max(-44.4, floor + 10) || (held && db > Math.max(-49.2, floor + 6)) }
}
export function speechBars({ drive, phase }: ReturnType<typeof speechAt>, reduced: boolean, restOpacity = REST_OPACITY) {
diff --git a/app/test/wave.test.ts b/app/test/wave.test.ts
index 4e89c33a..b287ba61 100644
--- a/app/test/wave.test.ts
+++ b/app/test/wave.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { silentSpeech, speechAt, speechBars, speechRestAt, speechSample } from '../src/shared/speechWave'
+import { micFloor, silentSpeech, speechAt, speechBars, speechRestAt, speechSample } from '../src/shared/speechWave'
const input = (db: number) => ({ me: Math.max(0, (db + 60) / 60), them: 0 })
const on = speechSample(silentSpeech, input(-25), 0)
@@ -56,4 +56,17 @@ describe('recording speech wave', () => {
expect(atStrength(0, true)).toEqual(atStrength(0, true).reverse())
expect(speechBars({ drive: .5, phase: 135 }, true).heights[2]).toBe(.35)
})
+
+ it('stays still over a noisy mic, measured against its own quietest tenth over the last minute', () => {
+ const recent: number[] = []
+ let speech = silentSpeech, floor = -Infinity
+ // a laptop mic whose room sits between -45 and -38 dB, louder than the fixed -44.4 dB gate
+ for (let i = 0; i < 100; i++) { floor = micFloor(recent, input(i % 2 ? -45 : -38)); speech = speechSample(speech, input(i % 2 ? -45 : -38), i * 100, floor) }
+ expect(floor).toBe(-45)
+ expect(speech.speaking).toBe(false)
+ expect(speechSample(speech, input(-25), 10000, micFloor(recent, input(-25))).speaking).toBe(true)
+ // no floor for the first five seconds: the fixed levels alone
+ expect(micFloor([], input(-40))).toBe(-Infinity)
+ expect(speechSample(silentSpeech, input(-40), 0, -Infinity).speaking).toBe(true)
+ })
})