Skip to content

vein: speech-to-text core — streaming dictation with hotwords - #1655

Merged
Evanfeenstra merged 7 commits into
mainfrom
vein-stt
Sep 7, 2026
Merged

vein: speech-to-text core — streaming dictation with hotwords#1655
Evanfeenstra merged 7 commits into
mainfrom
vein-stt

Conversation

@Evanfeenstra

@Evanfeenstra Evanfeenstra commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

What

Streaming speech-to-text inside vein over sherpa-onnx, per the rewritten §4 of vein/plans/local-desktop-and-stt.md. Dictation over a WebSocket is the product surface; workflows sit around the recognizer as the learning loop ("dream cycles", §4.8). No STT workflow step in v1.

  • src/audio/stt.ts — service: model download + sha256 verify + tar xjf, cached recognizers, streams (PCM16 in → partial/final events out), two-recognizer mode (fast greedy NeMo model for partials, hotword-capable Zipformer for finals + endpointing), batch transcribe. sherpa-onnx-node is an optionalDependency, lazy-imported; without it /audio/* answers 501 and everything else is untouched.
  • src/audio/hotwords.ts — contextual biasing. Two verified gotchas baked in: sherpa needs modelingUnit: "bpe" (unset → cjkchar → silent no-op), and a bpe.vocab the released models don't ship, synthesized from tokens.txt. Named lists under <dataDir>/audio/hotwords/ are the dream cycle's promotion artifact.
  • src/audio/sessions.ts — finals + user corrections per session (training data for the dream cycle).
  • src/audio/ws.tsGET /audio/stream via raw ws on the Node server (@hono/node-ws doesn't support node-server 2.x). Bearer or ?key=.
  • src/audio/routes.ts/audio/models (+ SSE download), /audio/transcribe, /audio/hotwords/:name, /audio/sessions/:id (+ corrections).
  • Web UI (web/src/dictation.ts, SettingsDialog, mic in ChatFlyout): gear → Settings → "Enable dictation" downloads the default pair and stores the choice in localStorage; a mic then appears in the AI chat input and dictates into it (partials live, finals replace them). Settings also has an inline hotwords list sent with every stream, for experimenting with biasing. Try it: VEIN_WORKSPACE_BACKEND=fs npx tsx src/server.ts (after npm run build:web), open the UI, gear, enable.
  • mcp /lab (mcp/src/lab/mount.ts attachLabAudio): the dictation socket works through the Express host too — mcp hooks the server's upgrade event, applies the lab Basic/x-api-token rule, and hands matching sockets to vein's createAudioUpgradeHandler. Verified end to end against a worktree mcp (401 without auth, 404 other paths, full replay with Basic auth, and the UI mic under /lab/).
  • createVein({ stt }), ctx.services.stt, VEIN_MODEL_DIR (alias of VEIN_MODEL_CACHE), VEIN_STT_MODEL, VEIN_STT_PARTIAL_MODEL.

Measured (M-series Mac, see doc §4.1)

model partials every hotwords notes
zipformer-en-kroko (57 MB) 1.3 s yes cased + punctuated; finals model
nemo-fast-conformer-en-80ms (103 MB) ~150 ms no (greedy-only in sherpa) partials model
nemo-fast-conformer-en-480ms (106 MB) ~570 ms no
nemotron-speech-en-80ms (463 MB) ~150 ms no accuracy ceiling, RTF ≈ 0.55

End to end over the socket at real-time pace: partials 50–100 ms behind the audio, final ~300 ms after end. Hotwords turned "on this FHIC swarm" into "on the Sphinx swarm" and "hive" into "Hive".

Tests

  • 21 new unit tests (scripted fake engine, ws protocol, auth), no addon needed; full suite 686/686.
  • npm run test:stt (opt-in VEIN_TEST_STT=1) downloads kroko and streams its bundled clip: 3/3 locally.

… hotwords

Streaming STT is the product surface; workflows learn around it (dream
cycles), no STT step. src/audio/: service (model download+verify, cached
recognizers, two-recognizer streams: fast greedy NeMo partials + hotword-
capable Zipformer finals, batch transcribe), catalog, hotwords compiler
(synthesized bpe.vocab — sherpa needs modelingUnit bpe or the list is a
silent no-op), sessions + corrections, /audio/stream WebSocket (raw ws on
the Node server; Bearer or ?key=), /audio/* routes. sherpa-onnx-node is an
optionalDependency, lazy-loaded; routes answer 501 without it.

Plan doc rewritten from the bake-off: measured latency/accuracy for kroko,
NeMo fast-conformer 80/480 ms, Nemotron; NeMo online transducers are
greedy-only in sherpa (no hotwords); sample-rate change aborts the process.
Mic → AudioWorklet → PCM16LE → /audio/stream, with model picker (+ SSE
download), inline hotwords, and editable finals that post corrections.
Inline HTML (tsc copies no assets); served before the key middleware so a
browser can load it, everything it calls stays gated.
Replaces the inline /audio/try page. A gear in the topbar opens a Settings
modal whose "Enable dictation" downloads the default model pair (kroko
finals + NeMo 80 ms partials) and stores the choice in localStorage;
installation stays a server fact via /audio/models. Once the chosen models
are confirmed installed, a mic appears in the chat input: partials render
live at the end of the textarea and finals replace them. A hotwords textarea
in Settings is sent inline with every stream for experimenting with biasing.
A WebSocket upgrade never enters Express, so the /lab bridge couldn't carry
/lab/audio/stream. vein now exposes createAudioUpgradeHandler (the piece
attachAudioWebSocket is built on) with an authorize hook; mcp hooks the
server's upgrade event, applies the lab Basic/x-api-token rule, lazily
builds the lab vein like the bridge does, and hands the socket over.
Other upgrade paths get a 404 instead of a hanging socket.
One resolver (src/model-dir.ts) for MiniLM and STT: VEIN_MODEL_DIR, then
the VEIN_MODEL_CACHE alias, then <cache root>/vein/models where the root is
VEIN_CACHE_DIR / XDG_CACHE_HOME / ~/.cache — the convention mcp's GAIA
checkout already uses, so the server's ~/.cache/vein volume persists models
with no new env. A pre-existing ~/.cache/vein-models keeps being used when
nothing is configured.
@Evanfeenstra
Evanfeenstra merged commit 99b5382 into main Sep 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant