Skip to content

feat(voice): transcribe dictation locally without a Soniox key - #432

Open
Lumea-art wants to merge 1 commit into
simplexai-labs:mainfrom
Lumea-art:feat/local-transcription
Open

Lumea-art wants to merge 1 commit into
simplexai-labs:mainfrom
Lumea-art:feat/local-transcription

Conversation

@Lumea-art

@Lumea-art Lumea-art commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Implements the proposal in #337. Dictation (Pocket notes and Voice Mode) can now run on the local computer with no Soniox key, so voice works offline and audio never leaves the machine. It is off by default: nothing changes until VOICE_LOCAL_ASR=on and VOICE_LOCAL_ASR_MODEL_DIR are set, and every existing deployment keeps Soniox exactly as today.

  • apps/voice-runtime: LocalASRProvider implements the existing ASRProvider / ASRStream seam with a streaming zipformer behind the optional sherpa-onnx-node engine. It emits the same partial / final / utterance_end / finalization_ack events, so DictationASRStream, ASREventQueue and the worker stay unchanged. agent.ts picks local or Soniox.
  • apps/node-services: the voice role starts only the ASR worker in local mode, without a key. VOICE_LOCAL_ASR=on requires VOICE_LOCAL_ASR_MODEL_DIR, so a misconfiguration fails at startup instead of at the first dictation. Recording still needs Soniox, because only Soniox labels speakers.
  • TeamHub: VoiceMediaPolicy gains dictation_supported, independent of voice_media_supported (recording), so the client offers dictation without offering meetings.
  • Web: the two dictation entry points prefer dictation_supported and fall back to voice_media_supported for older servers.
  • Docs and .env.example explain how to download the Apache-2.0 bilingual model and enable it.

Measured on Ubuntu 22.04, CPU only, two threads: the 190 MB int8 bilingual model decodes at RTF 0.04 (about 25x realtime) and the first partial arrives under 60 ms; four concurrent streams stay at an aggregate RTF of 0.043. The 25 MB Chinese model runs at RTF 0.015.

Review fixes (rebased onto 1c35212)

  • P1, session creation — createVoiceSession now skips the Soniox key only for chat_dictation when VOICE_LOCAL_ASR is on. hardware_control still requires Soniox, and dictation without the local engine still needs it. Added voice_local_asr_test.go: local dictation returns 201, recording returns 503, and Soniox dictation without a key returns 503.
  • P1, engine selection — spawnWorker now sets VOICE_LOCAL_ASR_MODEL_DIR only for a local binding and blanks it for key-bound workers. The voice-runtime agent also prefers a non-empty SONIOX_API_KEY over the local directory, so a leaked directory cannot hijack Soniox jobs. The now-unreachable no-diarization warning was removed, and LocalASRProvider's comment says dictation only.
  • Recognizer cache — LocalASRProvider clears its cached recognizer promise when a load fails, so a transient engine error is retried instead of poisoning every later stream. Added a test that fails the first load and succeeds the second.
  • Kept upstream TEAMHUB_VOICE_TOOLS_BIN, providerProxy, and the worker-start changes from main while resolving the rebase conflicts.

How it was verified

  • TeamHub internal/config and internal/app: local dictation / recording / Soniox dictation table, config parsing, existing purpose-provider test.
  • Node Services: typecheck, tests/voice/local-asr-worker.test.ts (9), including worker bindings and config validation.
  • Voice Runtime: src/local-asr.test.ts (7), including the recognizer retry; typecheck and lint on the changed files.
  • The full voice-runtime suite still has two unrelated failures in this environment (live-worker audio timing, provider-proxy network_reset vs network_refused); both are untouched by this PR.
  • Real-engine smoke, not part of CI: the pinned sherpa-onnx-node loaded the bilingual model and transcribed the model's test wavs through the same provider shape; numbers are in Voice: transcribe locally without a Soniox key #337.

Boundary

  • Dictation only. Recording and archive recovery still use Soniox, and a local transcript has no speaker labels, punctuation or casing. A Soniox key, when present, keeps dictation on Soniox.
  • No settings UI: the engine is enabled by deployment environment, as the proposal's first milestone says. Packaging the model through models.json and shipping the addon in the desktop runtime are follow-ups; the sherpa-onnx-node packaging direction is still to confirm in Voice: transcribe locally without a Soniox key #337.
  • sherpa-onnx-node is pinned to 1.12.14 because the current 2.x build needs a newer libstdc++ than Ubuntu 22.04 provides. It is an optional dependency and is marked external in the desktop bundle.
  • The full CI gate passed; the node-services suite is a heavy lane and is not run by PR CI, so the handler and worker tests above were run locally.

@Lumea-art
Lumea-art force-pushed the feat/local-transcription branch from f1a9883 to 1ad406c Compare November 21, 2026 12:34
@Lumea-art
Lumea-art marked this pull request as ready for review November 21, 2026 12:41

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes (2 P1)

Scope: base main, merge base fb6812dc; 1 commit and 24 files reviewed at 1ad406c5. Loaded the ponytail-review skill. coderbook and karpathy-guidelines were not loaded, so their review passes were applied from the skill's checklist only. Ran in a separate session.

Findings

P1

1. TeamHub still refuses to create a dictation session without a Soniox key, so local dictation never starts (apps/teamhub/internal/app/handlers_voice_media.go:52-63)

createVoiceSession resolves voicekey.Soniox for every purpose except chat_live. If the key is empty, it returns voicemedia.ErrProviderUnavailable, which writeVoiceMediaError (handlers_voice_media.go:268) turns into 503 VOICE_MEDIA_UNAVAILABLE. This PR does not touch this handler. The scenario the PR describes is VOICE_LOCAL_ASR=on, a model directory set, and no Soniox key. In that setup:

  • voice_media_policy.go:33 reports dictation_supported: true, so Pocket notes and Voice Mode show dictation.
  • node-services starts the local ASR worker.
  • The first POST /voice-sessions with purpose: chat_dictation then fails with 503.

Nothing in the PR reaches the new LocalASRProvider end to end. The PR's tests cover config parsing, workerKeys and a Web flag. None of them create a session.

Fix: when purpose == PurposeChatDictation && a.cfg.Voice.LocalASR, skip the key requirement. Keep it for hardware_control, which records and needs diarization. Add a handler test that creates a chat_dictation session with no Soniox key and LocalASR on, plus one that shows hardware_control is still refused.

2. Setting VOICE_LOCAL_ASR_MODEL_DIR alone switches every ASR job, recording transcripts included, to the local engine, even when a Soniox key is present (apps/voice-runtime/src/agent.ts:432-466, apps/node-services/src/voice/service.ts:278-288)

spawnWorker spreads the node-services environment (...env) into each child and only blanks SONIOX_API_KEY and XAI_API_KEY. So the ASR worker always inherits VOICE_LOCAL_ASR_MODEL_DIR. In the worker:

  • agent.ts picks LocalASRProvider whenever config.localAsrModelDir is non-empty, before it looks at sonioxApiKey.
  • The voice-runtime config never reads VOICE_LOCAL_ASR.

The linger-voice-runtime agent (agent.ts) also serves hardware_control captures. TeamHub dispatches every purpose except Live to it (internal/voicemedia/livekit_provider.go:133-137). Concrete cases:

  • A deployment sets VOICE_LOCAL_ASR=on plus the model directory and later adds a Soniox key, which docs/voice.md says "keeps transcription on Soniox". Its dictation and its recording transcripts now run locally, with no speaker labels, punctuation or casing. The only trace is the new warning log.
  • VOICE_LOCAL_ASR=off with the directory still exported behaves the same way.

The PR body ("Recording still needs Soniox") and the docs both contradict this. The node-services test keeps dictation on Soniox when a key and the local engine exist checks only workerKeys, so it misses the problem. The worker itself decides the opposite.

Fix: the supervisor should decide the engine, not the inherited environment. In spawnWorker, set VOICE_LOCAL_ASR_MODEL_DIR: binding.kind === "local" ? config.localAsrModelDir : "", the same way the provider keys are blanked. Then the warning branch at agent.ts:462-466 cannot be reached and can be deleted. Also fix the LocalASRProvider doc comment, which says it serves "Dictation and recording transcription" (local-asr.ts:613). Add a test on the spawned env, or make agent.ts prefer a non-empty Soniox key.

Verified as fine

  • The recorder worker never uses the local engine. main.ts:27 routes --recorder to recorder-agent.ts, which this PR does not change, and workerKeys starts the recorder only with a Soniox key (service.ts:97-109).
  • Worker reconcile treats local as a stable digest ("local"), so key polling does not restart the local ASR worker (service.ts:172-178).
  • Older clients and servers: the Web side falls back to voice_media_supported when dictation_supported is absent (use-pocket-dictation.ts:47, voice-mode-controls.tsx:49). The field is optional in the contract, and the generated files match the OpenAPI edit.
  • Local-only Web dictation does not need LiveKitProvider, which mounts only on voice_media_supported (voice-backend-controller.tsx:137). Pocket dictation opens its own session through openVoiceMode (use-pocket-dictation.ts:70-96).
  • The config is validated in one module per app (node-services/src/voice/config.ts, teamhub/internal/config/config.go:497). Env vars are listed in .env.example and scripts/env-inventory.json. sherpa-onnx-node is optional, loaded through a lazy import(), and marked external in the desktop bundle.
  • LocalASRStream keeps one stream handle per dictation stream and shares one recognizer. Events and offsets follow the ASRStream contract that ASREventQueue consumes.
  • No CJK in the added lines or in the commit message.

Not verified

  • The real sherpa-onnx-node behaviour (the tests use a fake engine). This covers what happens after a failed addon load, where the provider caches the rejected recognizer promise for the worker's lifetime.

Process notes

  • One commit, no merge or fixup commits. The branch is up to date with main. The merge state is BLOCKED only because it is waiting for review.

CI

All checks pass (changes, computer-go, contracts, desktop, installer, packages, teamhub, teamhub-cli, web, repository-gate, web tests 1/2 and 2/2, web-static). No CI job runs the dictation session creation path that finding 1 breaks. I ran no tests locally.

Automated review by Claude Code


Automated review of 1ad406c by Claude Code.

@DolphinMiner

Copy link
Copy Markdown
Contributor

Nice reuse of the ASRProvider seam, but there are two blockers plus merge conflicts:

createVoiceSession (handlers_voice_media.go) still requires a Soniox key for chat_dictation, so local dictation without a key fails with 503 before reaching LocalASRProvider.
spawnWorker inherits VOICE_LOCAL_ASR_MODEL_DIR, and agent.ts prefers it over SONIOX_API_KEY without checking VOICE_LOCAL_ASR—hijacking Soniox dictation and meeting recordings whenever the dir is set. Blank VOICE_LOCAL_ASR_MODEL_DIR in spawnWorker unless binding.kind === "local".

Also please clear #recognizer on load failure so transient errors aren't cached permanently, rebase onto main, and let's confirm the sherpa-onnx-node packaging direction in #337 before merging.

@Lumea-art
Lumea-art force-pushed the feat/local-transcription branch from 1ad406c to dba1c76 Compare November 26, 2026 15:44
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Thanks — both P1s and the recognizer cache are fixed, rebased onto 1c35212b.

  1. Session creation: createVoiceSession skips the Soniox key only for chat_dictation when VOICE_LOCAL_ASR is on; hardware_control and non-local dictation still require it. Added a handler table test: local dictation → 201, recording → 503, Soniox dictation without a key → 503.
  2. Engine selection: spawnWorker sets VOICE_LOCAL_ASR_MODEL_DIR only for a local binding and blanks it otherwise; the runtime agent also prefers a non-empty SONIOX_API_KEY, so a leaked directory cannot hijack recording. Removed the unreachable warning and corrected the provider comment.
  3. Recognizer cache: a failed load now clears #recognizer, so the next stream retries; added a test that fails once and succeeds on retry.

Focused checks pass: TeamHub config + handler tests, node-services typecheck and 9 voice tests, voice-runtime local-asr 7 tests. The full voice-runtime suite has two unrelated failures here (live-worker timing, provider-proxy error classification), both in files this PR does not touch. Packaging direction is still open in #337, as you noted.

@Lumea-art
Lumea-art force-pushed the feat/local-transcription branch from dba1c76 to 52065dd Compare November 26, 2026 15:48

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes (1 P1, 1 P3)

Scope: follow-up on 1ad406c. The branch was rebased onto main (merge base 1c35212b), so I re-reviewed the full merge-base diff: 1 commit and 26 files (lockfile and generated contracts checked only for consistency). Helper skills: coderbook, ponytail-review and karpathy-guidelines were not loaded this run; I applied the review checklist from the linger-pr-review instructions. The review ran in a separate session.

Previous findings

  • Resolved: dictation session rejected without a Soniox key. apps/teamhub/internal/app/handlers_voice_media.go:55 skips the key check only for chat_dictation when VOICE_LOCAL_ASR is on. voice_local_asr_test.go covers three cases: local dictation returns 201, recording returns 503, and Soniox dictation without a key returns 503.
  • Resolved: the model directory overrode Soniox. apps/node-services/src/voice/service.ts:285 passes VOICE_LOCAL_ASR_MODEL_DIR only to a local binding and blanks it for key-bound workers. apps/voice-runtime/src/agent.ts:47 also prefers a non-empty SONIOX_API_KEY.

Findings

P1

  • apps/voice-runtime/src/local-asr.ts:191: finalize() drops the audio still buffered at the end of a turn. A sherpa-onnx streaming zipformer decodes in fixed chunks. isReady() returns true only when a full chunk plus its right context is buffered, which is roughly 0.3–0.6 s for the bilingual model. Right now finalize() runs #decode(), emits final and finalization_ack for the current hypothesis, and then calls recognizer.reset(). It never feeds tail padding, so the trailing audio is never decoded into this turn.
    • Failure scenario: DictationASRStream.commit() (dictation-asr.ts:116) is the manual-commit path, used for example when Voice Mode sends a turn. If the user says "…send it to Bob" and commits right away, the turn is published without "Bob". Depending on how reset treats the unprocessed frames, the dropped words are either lost or show up at the start of the next turn.
    • Soniox's <fin> finalizes all audio sent so far, so this is a behavior difference from the provider this replaces.
    • The test double in local-asr.test.ts hides the problem: FakeRecognizer.acceptWaveform sets ready = true after every frame, so it never models chunk buffering.
    • Fix: in finalize(), accept about 0.5–0.66 s of zero samples (the tail padding sherpa-onnx's own examples use) before #decode(). Don't count the padding in #samples. Then flush and reset. Do the same before inputFinished() in finish(). Make the fake keep audio pending until a chunk threshold, and add a test where the last words arrive below that threshold.

P3

  • docs/voice.md:67: "a platform without a loadable build keeps dictation on Soniox" is only true when a Soniox key exists, and then Soniox wins anyway (agent.ts:47). Without a key, TeamHub still reports dictation_supported: true (voice_media_policy.go:32). Every dictation job then fails when it tries to load sherpa-onnx-node. Reword the sentence: local dictation requires a loadable build, and a missing addon makes dictation fail.

Verified as fine

  • Worker selection: workerKeys (apps/node-services/src/voice/service.ts:85) starts only the asr worker in local mode, with digest "local". When a key is added or removed, apply replaces the worker (service.ts:314), and the recorder stays stopped without Soniox.
  • Recording still needs Soniox: createVoiceSession keeps the key check for hardware_control (handlers_voice_media.go:55). These three are the only purposes (voicemedia/types.go:22).
  • Old-server compatibility: Web falls back with dictation_supported ?? voice_media_supported (use-pocket-dictation.ts:41, voice-mode-controls.tsx:48). The contract adds an optional field, and the generated Go/TS match it.
  • Config: VOICE_LOCAL_ASR is validated in both TeamHub (config.go:509) and node-services (voice/config.ts:49). VOICE_LOCAL_ASR_MODEL_DIR is in scripts/env-inventory.json. LocalASRProvider.#load clears a rejected recognizer promise (local-asr.ts:142), so a failed load is retried.
  • No CJK in added lines or the commit message.

Process notes

  • Single commit with no merge commits; the branch is up to date with main.

CI

  • All checks pass. The PR CI does not run the voice-runtime and node-services voice tests, so the new local-ASR tests are covered only by the author's local runs. I didn't run any tests myself.

Automated review by Claude Code


Automated review of 52065dd by Claude Code.

@Lumea-art
Lumea-art force-pushed the feat/local-transcription branch from 52065dd to 4495071 Compare November 27, 2026 00:05
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Fixed both in 44950715:

  • P1, tail padding: finalize() and finish() now feed 0.5 s of zero samples (sherpa-onnx's own streaming example padding) before decoding, so the last partial chunk is decoded into that turn. The padding is marked padding: true and is not counted in #samples, so event offsets still describe only the caller's audio. The tail is decoded with #decode(false): its text goes into the final/flush that follows instead of emitting a new partial or endpoint. The fake recognizer now buffers until a 1,600-sample chunk, and two tests cover the case: 1,000 samples + manual commit → final "hello world" at 0–63 ms; 1,000 samples + end of input → final "hello world" at 0–63 ms.
  • P3, docs: reworded to "local dictation requires a loadable build; if the addon is missing every dictation job fails to load the engine. A Soniox key keeps dictation on Soniox and does not need the addon."

local-asr.test.ts is 9/9; voice-runtime typecheck and prettier are clean. The full-file suite still has the two unrelated failures noted before (live-worker timing, provider-proxy error classification).

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with nits (1 P3)

Follow-up on 52065dd. Scope: base main, merge base 1c35212b; 1 commit and 26 files reviewed, with the delta since the previous review (local-asr.ts, local-asr.test.ts, docs/voice.md) read in full. Helper skills loaded: coderbook. ponytail-review and karpathy-guidelines were not loaded, and their checks were applied from the review checklist instead. Ran in a separate session.

Previous findings

  • Resolved: P1, a manual commit finalized before the last partial chunk was decoded. finalize() and finish() now call #acceptTailPadding() (0.5 s of silence) before #decode(false) (apps/voice-runtime/src/local-asr.ts:199-215). The padding does not count toward #samples, so offsets still describe the audio the caller sent. FakeRecognizer now decodes only full 1,600-sample chunks (local-asr.test.ts:41-68). The new tests "decodes the last partial chunk before a manual commit" and "decodes the last partial chunk before end of input" send 1,000 samples. That is less than one chunk, so both tests fail without the padding.
  • Resolved: P3, the docs said a missing addon falls back to Soniox. docs/voice.md:66-69 now says local dictation needs a loadable build, that every dictation job fails without it, and that a Soniox key keeps dictation on Soniox.

Findings

P3

  • apps/voice-runtime/src/local-asr.ts:29: the new padding?: boolean on LocalASRStreamHandle.acceptWaveform exists only for the test double. The real OnlineStream (sherpa-onnx-node.d.ts:3) has no such field and ignores it. Only FakeRecognizer reads it, to leave the padding out of its own sample count. The field isn't needed: #decode(false) skips both partials and endpoints during the tail, and the stream's offsets come from #samples, which never includes the padding. If the fake counted the padding as well, the new tests would still produce the same events. Drop the field and the if (!padding) in the fake so the production interface matches the engine.

Verified as fine

  • After the tail padding in finalize(), recognizer.reset(handle) still runs. Skipping endpoint handling in #decode(false) therefore can't emit a stray utterance_end before the finalization_ack (local-asr.ts:242-261).
  • In finish(), the padding is accepted before inputFinished(), the order sherpa-onnx's streaming examples use (local-asr.ts:207-215).
  • Engine selection across the whole PR: workerKeys binds the ASR worker locally only when no Soniox key exists (apps/node-services/src/voice/service.ts:54-65). spawnWorker clears VOICE_LOCAL_ASR_MODEL_DIR for key-bound workers (service.ts:285-289). The runtime prefers a non-empty Soniox key (apps/voice-runtime/src/agent.ts:47-57). TeamHub skips the key check only for chat_dictation with LocalASR on (apps/teamhub/internal/app/handlers_voice_media.go:55).
  • Web falls back to voice_media_supported when an older server omits dictation_supported (voice-mode-controls.tsx:48, use-pocket-dictation.ts:46).
  • No CJK in added lines or in the commit message, and no merge commits.

Process notes

  • None to act on. The branch is based on the current main merge base, 1c35212b.

CI

  • At review time only changes had passed; every other check (teamhub, packages, contracts, desktop, web tests, repository-gate, and others) was still pending. I ran no tests myself: this worktree has no node_modules, and the delta's behavior is covered by the two new unit tests. The real-engine path (sherpa-onnx-node with the padding) is not exercised by CI and remains unverified here.

Automated review by Claude Code


Automated review of 4495071 by Claude Code.

Dictation can run on this computer without a Soniox key when VOICE_LOCAL_ASR=on and VOICE_LOCAL_ASR_MODEL_DIR names a streaming zipformer. LocalASRProvider implements the existing ASRProvider seam; the supervisor starts only the ASR worker locally and keeps recording on Soniox. TeamHub exposes dictation_supported independently of recording.

Review fixes: createVoiceSession allows local dictation without a key while recording still requires Soniox; spawnWorker sets the model directory only for a local binding and the runtime prefers a Soniox key when present; a failed recognizer load is retried instead of cached.
@Lumea-art
Lumea-art force-pushed the feat/local-transcription branch from 4495071 to 6069432 Compare November 27, 2026 00:11
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Fixed in 60694325, rebased onto 6a511c15:

  • Removed padding?: boolean from LocalASRStreamHandle.acceptWaveform; the production interface now matches the sherpa OnlineStream exactly.
  • The fake no longer needs a flag: its acceptWaveform treats an all-zero frame as silence for its sample count, and the speech frames in the tests are Int16Array(...).fill(1). Tail padding still flushes the chunk, while #decode(false) keeps it out of partial/endpoint events and #samples keeps it out of offsets.
  • local-asr.test.ts 9/9, voice-runtime typecheck and prettier clean.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Follow-up on 4495071. Merge base 6a511c15 (current main); 1 commit, 26 files reviewed. The branch was rebased, so I compared the two versions with git range-diff. The only PR-side change is the padding fix.

Previous findings

  • Resolved: test-only padding field on the production stream interface. apps/voice-runtime/src/local-asr.ts:24 now accepts only { sampleRate, samples }. The fake recognizer in local-asr.test.ts skips all-zero tail padding when it counts samples, and the tests send non-zero PCM.

Verified as fine

  • Engine selection: the supervisor passes VOICE_LOCAL_ASR_MODEL_DIR only to a local binding and clears it for key-bound workers (apps/node-services/src/voice/service.ts:285). The worker still prefers a non-empty Soniox key (apps/voice-runtime/src/agent.ts:47).
  • Key bypass is limited to dictation: TeamHub skips the Soniox key lookup only when the purpose is chat_dictation and LocalASR is on (apps/teamhub/internal/app/handlers_voice_media.go:55). voice_local_asr_test.go covers recording and Soniox dictation, and both still return 503. The policy reports dictation_supported only when voice is available (voice_media_policy.go:33). Web falls back to voice_media_supported when an older server omits the field.
  • Config consistency: TeamHub and node-services read the same VOICE_LOCAL_ASR from the shared .env, and Compose loads that file through env_file. Node-services fails at startup when the variable is on but the model directory is missing (apps/node-services/src/voice/config.ts:25). VOICE_LOCAL_ASR_MODEL_DIR is listed in scripts/env-inventory.json:154.

CI: changes and repository-gate were still pending when I reviewed. I ran no tests.

Automated review by Claude Code


Automated review of 6069432 by Claude Code.

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.

2 participants