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.

12.1 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { AFTER_MEETING_RTF, asrCandidates, KEEPS_UP_RTF, LAGS_A_LITTLE_RTF, pickAsr, pickBySpeed, SPEED_CHECK_VERSION, speedKey } from '../src/asr'
import { machines } from './fixtures'
import real from '../../../catalog/catalog.json'
import type { Catalog } from '../src/types'

const catalog = real as unknown as Catalog

describe('pickAsr', () => {
  it('turbo on a 32 GB Mac', () => {
    expect(pickAsr(machines.m1max32, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
  })
  it('turbo on an 8 GB Mac (the notes model never runs while recording)', () => {
    expect(pickAsr(machines.mac8, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
  })
  it('turbo on 16 GB and 128 GB', () => {
    expect(pickAsr(machines.m3air16, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
    expect(pickAsr(machines.m4max128, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
  })
  it('small on a machine with under 8 GB', () => {
    expect(pickAsr({ ...machines.mac8, totalRamGB: 6 }, catalog).model.id).toBe('whisper-small-q5_1')
  })
  it('names small as the fallback when turbo is picked', () => {
    expect(pickAsr(machines.m1max32, catalog).fallback?.id).toBe('whisper-small-q5_1')
    expect(pickAsr({ ...machines.mac8, totalRamGB: 6 }, catalog).fallback).toBeUndefined()
  })
  it('skips a model that failed verification', () => {
    expect(pickAsr(machines.m1max32, catalog, { exclude: ['whisper-large-v3-turbo-q5_0'] }).model.id).toBe('whisper-small-q5_1')
  })
})

describe('pickAsr without graphics (Windows and Linux)', () => {
  it('Whisper small on the processor alone: turbo is too slow to keep up there', () => {
    expect(pickAsr(machines.winLaptop8, catalog).model.id).toBe('whisper-small-q5_1')
    expect(pickAsr({ ...machines.winLaptop8, totalRamGB: 32 }, catalog).model.id).toBe('whisper-small-q5_1')
  })
  it('turbo with a graphics card', () => {
    expect(pickAsr(machines.linux3060, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
  })
})

describe('the measured speed check (Windows and Linux)', () => {
  const ids = (l: { id: string }[]) => l.map((a) => a.id)
  it('a Mac never sees the last-resort models: its pick and fallback are exactly as before', () => {
    for (const m of [machines.m1max32, machines.mac8, machines.m3air16, machines.m4max128]) {
      expect(pickAsr(m, catalog).model.id).toBe('whisper-large-v3-turbo-q5_0')
      expect(pickAsr(m, catalog).fallback?.id).toBe('whisper-small-q5_1')
    }
    expect(pickAsr(machines.m1max32, catalog, { exclude: ['whisper-large-v3-turbo-q5_0', 'whisper-small-q5_1'] }).model.id).not.toMatch(/tiny|base/)
    expect(asrCandidates(machines.m1max32, catalog)).toEqual([])
  })
  it('with graphics: turbo first, then down to the smallest', () => {
    expect(ids(asrCandidates(machines.linux3060, catalog))).toEqual(['whisper-large-v3-turbo-q5_0', 'whisper-small-q5_1', 'whisper-base-q5_1', 'whisper-tiny-q5_1'])
  })
  it('a Ryzen 7 7735U: with its Radeon 680M every model is tried, on the processor alone small and smaller', () => {
    expect(ids(asrCandidates(machines.ryzen680m, catalog))).toEqual(['whisper-large-v3-turbo-q5_0', 'whisper-small-q5_1', 'whisper-base-q5_1', 'whisper-tiny-q5_1'])
    expect(ids(asrCandidates(machines.ryzen7735u, catalog))).toEqual(['whisper-small-q5_1', 'whisper-base-q5_1', 'whisper-tiny-q5_1'])
  })
  it('on the processor alone turbo is never tried (it measured 4 to 9 times too slow)', () => {
    expect(ids(asrCandidates(machines.winLaptop8, catalog))).toEqual(['whisper-small-q5_1', 'whisper-base-q5_1', 'whisper-tiny-q5_1'])
  })
  it('leaves out models that failed verification', () => {
    expect(ids(asrCandidates(machines.winLaptop8, catalog, { exclude: ['whisper-small-q5_1'] }))).toEqual(['whisper-base-q5_1', 'whisper-tiny-q5_1'])
  })
  it('every model is pinned with a sha256', () => {
    for (const a of catalog.asr) expect(a.sha256).toMatch(/^[a-f0-9]{64}$/)
  })
})

describe('pickBySpeed', () => {
  const list = [{ id: 'turbo' }, { id: 'small' }, { id: 'base' }, { id: 'tiny' }]
  const timed = (rtf: Record<string, number | null>) => { const asked: string[] = []; return { asked, measure: async (m: { id: string }) => { asked.push(m.id); return rtf[m.id] } } }
  it('keeps the first (best) model that reads a clip in half its length or less, and times nothing smaller', async () => {
    const t = timed({ turbo: 0.12 })
    expect(await pickBySpeed(list, t.measure)).toEqual({ model: list[0], rtf: { turbo: 0.12 } })
    expect(t.asked).toEqual(['turbo'])
  })
  it('falls back down the list until one keeps up; exactly 0.5 still does', async () => {
    const t = timed({ turbo: 4.4, small: 0.88, base: 0.5 })
    expect(await pickBySpeed(list, t.measure)).toEqual({ model: list[2], rtf: { turbo: 4.4, small: 0.88, base: 0.5 } })
    expect(KEEPS_UP_RTF).toBe(0.5)
  })
  // #107: base and tiny are very weak outside English. small may lag a little behind live rather than fall back to them:
  // whisper skips silence (VAD), so with both sides talking about half the time it still about keeps up over a meeting.
  it('a model allowed to lag a little is kept up to 1.25 times the clip\'s length, before anything smaller', async () => {
    const t = timed({ turbo: 4.4, small: 0.88, base: 0.3 })
    const lags = (m: { id: string }) => m.id === 'small'
    expect(await pickBySpeed(list, t.measure, { lagsOk: lags })).toEqual({ model: list[1], rtf: { turbo: 4.4, small: 0.88 } })
    expect(LAGS_A_LITTLE_RTF).toBe(1.25)
    expect((await pickBySpeed(list, timed({ turbo: 4.4, small: 1.2, base: 0.3 }).measure, { lagsOk: lags })).model).toBe(list[1])
    // too slow even so: down the list as before
    expect((await pickBySpeed(list, timed({ turbo: 4.4, small: 1.4, base: 0.3 }).measure, { lagsOk: lags })).model).toBe(list[2])
  })
  it('a run that ran out of time counts as too slow', async () => {
    const t = timed({ turbo: null, small: null, base: null, tiny: 0.19 })
    expect((await pickBySpeed(list, t.measure)).model).toBe(list[3])
  })
  // a computer that can't keep up live still records: the transcript is written from the recording after the meeting
  it('none keeps up: the best one that read the clip at all is kept for after the meeting, with every time it measured', async () => {
    const t = timed({ turbo: null, small: null, base: 0.8, tiny: 0.6 })
    expect(await pickBySpeed(list, t.measure)).toEqual({ model: list[2], rtf: { turbo: null, small: null, base: 0.8, tiny: 0.6 }, afterMeeting: true })
  })
  it('none read the clip in its own length: the fastest one, after the meeting', async () => {
    expect(await pickBySpeed(list, timed({ turbo: 9, small: 2, base: 1.1, tiny: 1.05 }).measure)).toMatchObject({ model: list[3], afterMeeting: true })
  })
  it('none finished at all: still the smallest, after the meeting, never no model', async () => {
    expect(await pickBySpeed(list, timed({ turbo: null, small: null, base: null, tiny: null }).measure)).toMatchObject({ model: list[3], afterMeeting: true })
  })
  it('graphics slower than the processor (a Radeon 680M through Vulkan): the processor is timed too, and kept where it keeps up', async () => {
    const asked: string[] = []
    const gpu: Record<string, number | null> = { turbo: 2, small: 0.9, base: 0.6 }, cpu: Record<string, number | null> = { small: 0.4, base: 0.2 }
    const measure = async (m: { id: string }, onCpu?: boolean) => { asked.push(`${m.id}${onCpu ? '@cpu' : ''}`); return (onCpu ? cpu : gpu)[m.id] }
    // turbo is never tried on the processor: it measured 4 to 9 times too slow there
    const r = await pickBySpeed(list, measure, { cpuToo: (m) => m.id !== 'turbo' })
    expect(r).toEqual({ model: list[1], rtf: { turbo: 2, small: 0.9 }, cpuRtf: { small: 0.4 }, cpu: true })
    expect(asked).toEqual(['turbo', 'small', 'small@cpu'])
  })
  it('graphics that keep up are kept: the processor is not timed', async () => {
    const asked: string[] = []
    const r = await pickBySpeed(list, async (m, onCpu) => { asked.push(`${m.id}${onCpu ? '@cpu' : ''}`); return 0.2 }, { cpuToo: () => true })
    expect(r).toEqual({ model: list[0], rtf: { turbo: 0.2 } })
    expect(asked).toEqual(['turbo'])
  })
  it('after the meeting on whichever was faster for that model', async () => {
    const r = await pickBySpeed(list, async (m, onCpu) => (m.id === 'small' ? (onCpu ? 0.7 : 0.95) : null), { cpuToo: (m) => m.id !== 'turbo', lagsOk: () => false })
    expect(r).toMatchObject({ model: list[1], afterMeeting: true, cpu: true })
  })
  // #107: base keeps up live, but small (or turbo) reads too slowly for live. Outside English base is poor, so the better
  // one is kept too, to read a meeting's recording after it ends; English keeps base live as before
  describe('the better model for other languages, read after the meeting', () => {
    const weak = (m: { id: string }) => m.id === 'base' || m.id === 'tiny'
    it('base live, small too slow for live but within twice the clip: small for other languages', async () => {
      const r = await pickBySpeed(list, timed({ turbo: null, small: 1.6, base: 0.3 }).measure, { weak, lagsOk: (m) => m.id === 'small' })
      expect(r).toEqual({ model: list[2], rtf: { turbo: null, small: 1.6, base: 0.3 }, multi: { model: list[1] } })
      expect(AFTER_MEETING_RTF).toBe(2)
    })
    it('turbo within twice the clip beats small', async () => {
      expect((await pickBySpeed(list, timed({ turbo: 1.9, small: 1.4, base: 0.3 }).measure, { weak })).multi).toEqual({ model: list[0] })
    })
    it('on the processor where that was faster for it', async () => {
      const r = await pickBySpeed(list, async (m, onCpu) => ({ turbo: null, small: onCpu ? 1.5 : null, base: 0.3 } as Record<string, number | null>)[m.id], { weak, cpuToo: (m) => m.id === 'small' })
      expect(r.multi).toEqual({ model: list[1], cpu: true })
    })
    it('none of the better ones within twice the clip, or a strong model live: no second model', async () => {
      expect((await pickBySpeed(list, timed({ turbo: null, small: 2.5, base: 0.3 }).measure, { weak })).multi).toBeUndefined()
      expect((await pickBySpeed(list, timed({ turbo: 1.5, small: 0.4 }).measure, { weak })).multi).toBeUndefined()
    })
    it('none keeps up live and base is kept for after the meeting: small instead for other languages', async () => {
      const r = await pickBySpeed(list, timed({ turbo: null, small: 1.8, base: 0.8, tiny: 0.6 }).measure, { weak })
      expect(r).toMatchObject({ model: list[2], afterMeeting: true, multi: { model: list[1] } })
    })
  })
})

describe('speedKey: the speed check runs again only when the computer changes', () => {
  it('carries the speed check version, so a change to how it picks measures again once (#107)', () => {
    expect(speedKey(machines.linux3060).startsWith(`${SPEED_CHECK_VERSION}|`)).toBe(true)
    expect(SPEED_CHECK_VERSION).toBe('v3')
  })
  it('the same computer gives the same key; other graphics or processor a new one', () => {
    const k = speedKey(machines.linux3060)
    expect(speedKey({ ...machines.linux3060, freeDiskGB: 1 })).toBe(k)
    expect(speedKey({ ...machines.linux3060, gpu: { kind: 'none', name: '', vramGB: 0 } })).not.toBe(k)
    expect(speedKey({ ...machines.linux3060, gpu: { ...machines.linux3060.gpu, name: 'NVIDIA GeForce RTX 4070' } })).not.toBe(k)
    expect(speedKey({ ...machines.linux3060, cpuModel: 'AMD Ryzen 7 7700' })).not.toBe(k)
    expect(speedKey({ ...machines.linux3060, cores: 6 })).not.toBe(speedKey({ ...machines.linux3060, cores: 12 }))
  })
})

describe('Parakeet in the speed check', () => {
  it('is judged by the rule the whisper models are: it reads live only where it keeps up with two voices', async () => {
    const { parakeetKeepsUp } = await import('../src/asr')
    expect(parakeetKeepsUp(0.21)).toBe(true)
    expect(parakeetKeepsUp(KEEPS_UP_RTF)).toBe(true)
    expect(parakeetKeepsUp(0.51)).toBe(false)
    // out of time, or not timed yet
    expect(parakeetKeepsUp(null)).toBe(false)
    expect(parakeetKeepsUp(undefined)).toBe(false)
  })
  it('is no whisper candidate: the whisper models are picked from the same list as before', () => {
    expect(catalog.asr.map((a) => a.id)).not.toContain(catalog.parakeet!.id)
    expect(asrCandidates(machines.m1max32, catalog)).toEqual([])
  })
})