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.

Transcripts: whisper on a graphics card (Windows/Linux) is checked on a known clip before a meeting uses it, and runs on the processor when it hears no words (#92 Adreno, #76 Radeon RX 9070 XT gave empty transcripts)

christianmatde36cfa081e6
diff --git a/app/src/main/asr/index.ts b/app/src/main/asr/index.ts
index 1c6ffecf..9f1467b5 100644
--- a/app/src/main/asr/index.ts
+++ b/app/src/main/asr/index.ts
@@ -8,6 +8,7 @@ import { echoConfidence } from './echo'
import { appleSpeechAvailable, installSpeechLocale, readSpeechLocales, speechDisagrees, speechFits, wantedSpeechLocale, type SpeechHost, type SpeechLocales } from './appleSpeech'
import { whisperLanguage, type Spoken } from '../../shared/spoken'
import { createWhisperServer, recoverer, vadModelPath, whisperServerPath, type WhisperServer } from './server'
+import { clipStart, hearsClip } from './speedCheck'
import { createTranscriber, type Line, type Transcribe } from './transcribe'
import { meetingWords, respell, whisperPrompt } from '../vocab'
import type { TranscriptPartial } from '../../shared/types'
@@ -118,7 +119,7 @@ function serverFor(model: string, pidFile: string | undefined, make?: (model: st
const key = `${model}|${pidFile}`
if (!server || serverKey !== key) {
void server?.stop()
- server = make ? make(model, pidFile) : createWhisperServer({ binary: whisperServerPath(), model, pidFile, vadModel: vadModelPath(), gpuFallback: process.platform !== 'darwin', onGpuOff: () => gpuOffListener?.() })
+ server = make ? make(model, pidFile) : createWhisperServer({ binary: whisperServerPath(), model, pidFile, vadModel: vadModelPath(), gpuFallback: process.platform !== 'darwin', onGpuOff: () => gpuOffListener?.(), checkGpu: async (url) => { const clip = clipStart(); return !clip || hearsClip(url, clip) } })
serverKey = key
}
return server
diff --git a/app/src/main/asr/server.ts b/app/src/main/asr/server.ts
index 63d4fa17..0d48d082 100644
--- a/app/src/main/asr/server.ts
+++ b/app/src/main/asr/server.ts
@@ -88,6 +88,11 @@ type Opts = {
gpuFallback?: boolean
/** told once when that happens (the speed check measured with the graphics, so it times again on the next start) */
onGpuOff?: () => void
+ /**
+ * With gpuFallback: does a launch on the graphics card hear words in a known clip? Some cards (#92 an Adreno, #76 a
+ * Radeon RX 9070 XT) load whisper and answer every request with nothing; then it runs on the processor instead.
+ */
+ checkGpu?: (url: string) => Promise<boolean>
}
/** a meeting relaunches a dead or hung server at most this often, waiting longer each time */
@@ -157,12 +162,26 @@ export function createWhisperServer(o: Opts) {
}
throw new Error('whisper-server did not start in time')
})()
- try { return await Promise.race([healthy, gone]) } catch (e) {
+ let up: string
+ try { up = await Promise.race([healthy, gone]) } catch (e) {
healthy.catch(() => {})
if (o.gpuFallback && !cpuOnly && (p.exitCode !== null || p.signalCode !== null)) { cpuOnly = true; console.error('whisper-server stopped while loading; starting it again without the graphics card'); o.onGpuOff?.() }
p.kill('SIGKILL')
throw e
}
+ if (o.gpuFallback && !cpuOnly && o.checkGpu) {
+ let hears = true
+ try { hears = await o.checkGpu(up) } catch (e) { console.warn('whisper-server: checking the graphics card failed', e) }
+ if (!hears) {
+ cpuOnly = true
+ console.error('whisper-server heard no words on the graphics card; starting it again without it')
+ o.onGpuOff?.()
+ if (child === p) { child = null; died = false }
+ p.kill('SIGKILL')
+ return launch()
+ }
+ }
+ return up
}
const self = {
diff --git a/app/src/main/asr/speedCheck.ts b/app/src/main/asr/speedCheck.ts
index 3df8c0c1..650d01d8 100644
--- a/app/src/main/asr/speedCheck.ts
+++ b/app/src/main/asr/speedCheck.ts
@@ -49,7 +49,7 @@ type MeasureOpts = {
* clip itself is stopped: null, too slow by far.
*/
export async function measureSpeed(model: string, o: MeasureOpts): Promise<{ rtf: number | null; gpuOff: boolean }> {
- const srv = o.server?.(model) ?? createWhisperServer({ binary: o.binary, model, vadModel: o.vadModel, gpuFallback: true, startTimeoutMs: 180_000, backoffMs: [0] })
+ const srv = o.server?.(model) ?? createWhisperServer({ binary: o.binary, model, vadModel: o.vadModel, gpuFallback: true, startTimeoutMs: 180_000, backoffMs: [0], checkGpu: (url) => hearsClip(url, readWav(readFileSync(o.clip)).subarray(0, 5 * 16000)) })
const samples = readWav(readFileSync(o.clip))
const clipMs = samples.length / 16
try {
@@ -69,6 +69,22 @@ export async function measureSpeed(model: string, o: MeasureOpts): Promise<{ rtf
}
}
+/**
+ * Does whisper at this address hear the clip's words? Some graphics cards (#92 an Adreno, #76 a Radeon RX 9070 XT) load
+ * whisper and answer every request with nothing, without an error: two words or more is hearing it.
+ */
+export async function hearsClip(url: string, samples: Float32Array, fetchFn?: typeof fetch): Promise<boolean> {
+ const lines = await createTranscriber({ url: async () => url, language: () => 'en', timeoutMs: 60_000, ...(fetchFn ? { fetchFn } : {}) })({ track: 'them', startMs: 0, samples })
+ return lines.map((l) => l.text).join(' ').trim().split(/\s+/).filter(Boolean).length >= 2
+}
+
+/** the first seconds of the speed clip, for checking a graphics card (none in a build without it) */
+export function clipStart(seconds = 5): Float32Array | null {
+ const clip = speedClipPath()
+ if (!clip) return null
+ try { return readWav(readFileSync(clip)).subarray(0, seconds * 16000) } catch { return null }
+}
+
/** The speed check's result, kept in one small file in the profile */
export function speedStore(file: string): Pick<SpeedDeps, 'load' | 'save'> & { forget(): void } {
return {
diff --git a/app/src/main/index.ts b/app/src/main/index.ts
index 83e76a10..33afd10a 100644
--- a/app/src/main/index.ts
+++ b/app/src/main/index.ts
@@ -800,7 +800,7 @@ app.whenReady().then(() => {
if (file?.endsWith(ownAudio)) tracks[t] = isFake() ? wavDecode(file) : helperDecode(audioHelperPath(), file)
}
if (!Object.keys(tracks).length) continue
- console.info('ASR', `transcribing ${m.id} from its recording: it was recorded before the speech model was in`)
+ console.info('ASR', `transcribing ${m.id} from its recording: it has no transcript yet`)
const done = await transcribeRecorded(m.id, tracks, () => !!activeMeeting())
win?.webContents.send('meetings:changed'); win?.webContents.send('transcript:speakers', m.id)
// notes that came out empty (no transcript then) are written now
diff --git a/app/test/asrServer.test.ts b/app/test/asrServer.test.ts
index 95951d74..9ae966c2 100644
--- a/app/test/asrServer.test.ts
+++ b/app/test/asrServer.test.ts
@@ -132,6 +132,32 @@ describe.skipIf(process.platform === 'win32')('whisper server', () => {
const third = await s.url()
await expect(s.wedged(third)).resolves.toMatch(/^http/)
})
+ // #92 (Adreno), #76 (Radeon RX 9070 XT): whisper loaded on the graphics card and answered every request with no words
+ it('off a Mac, a server whose graphics card hears no words in a known clip starts again without it, before any meeting uses it', async () => {
+ const bin = fakeBinary()
+ const args = () => JSON.parse(readFileSync(join(bin, '../args'), 'utf8')) as string[]
+ const off = vi.fn()
+ const checked: boolean[] = []
+ const s = make(bin, { gpuFallback: true, onGpuOff: off, checkGpu: async () => { const ok = checked.length > 0; checked.push(ok); return ok } })
+ const url = await s.url()
+ expect(args()).toContain('-ng')
+ expect(s.cpuOnly).toBe(true)
+ expect(off).toHaveBeenCalledTimes(1)
+ // checked once, on the graphics card; the processor isn't checked
+ expect(checked).toEqual([false])
+ expect(await alive(url)).toBe(true)
+ })
+ it('a graphics card that hears the clip keeps the graphics, and a Mac is never checked', async () => {
+ const check = vi.fn(async () => true)
+ const bin = fakeBinary()
+ await make(bin, { gpuFallback: true, checkGpu: check }).url()
+ expect(JSON.parse(readFileSync(join(bin, '../args'), 'utf8'))).not.toContain('-ng')
+ expect(check).toHaveBeenCalledTimes(1)
+ const mac = vi.fn(async () => false)
+ await make(fakeBinary(), { checkGpu: mac }).url()
+ expect(mac).not.toHaveBeenCalled()
+ })
+
it('a Mac keeps its graphics however often it hangs (Metal)', async () => {
const bin = fakeBinary(0, ['wedge'])
const s = make(bin)
diff --git a/app/test/gpuHears.test.ts b/app/test/gpuHears.test.ts
new file mode 100644
index 00000000..5ff4c0a4
--- /dev/null
+++ b/app/test/gpuHears.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest'
+import { hearsClip } from '../src/main/asr/speedCheck'
+
+// a fake whisper-server answer with these words
+const answer = (text: string): typeof fetch => (async () => new Response(JSON.stringify({ detected_language: 'english', detected_language_probability: 0.99, segments: text ? [{ start: 0, end: 3, text }] : [] }))) as unknown as typeof fetch
+const speech = new Float32Array(16000 * 4).map((_, i) => Math.sin(i / 8) * 0.3)
+
+// #92, #76: some graphics cards load whisper and answer with nothing
+describe('does whisper on the graphics card hear the clip', () => {
+ it('words back: yes', async () => {
+ expect(await hearsClip('http://127.0.0.1:1', speech, answer(' The quick brown fox jumps'))).toBe(true)
+ })
+ it('nothing, or a lone word, back: no', async () => {
+ expect(await hearsClip('http://127.0.0.1:1', speech, answer(''))).toBe(false)
+ expect(await hearsClip('http://127.0.0.1:1', speech, answer(' you'))).toBe(false)
+ })
+})