Skip to content

feat(voice): dictate without a Soniox key on a local speech model - #643

Open
cnYui wants to merge 1 commit into
simplexai-labs:mainfrom
cnYui:feat/voice-local-dictation
Open

cnYui wants to merge 1 commit into
simplexai-labs:mainfrom
cnYui:feat/voice-local-dictation

Conversation

@cnYui

@cnYui cnYui commented Nov 24, 2026 •

Copy link
Copy Markdown

What and why

Dictation (the Message box, Voice Mode and Pocket notes) needed a Soniox key. With none saved it now runs on a local speech model and a text rewrite of the person's choice, so a deployment with no speech key can still dictate.

  • Local recognition. SenseVoiceSmall int8 through sherpa-onnx, ported from SpeakMore (MIT; NOTICE and third_party/licenses/speakmore-MIT.txt updated). Node Services downloads the model (~230 MB) once into AGENT_HOME/models the first time it starts with no Soniox key (Hugging Face, or hf-mirror.com first for SIMPLEX_REGION=cn), resumable, pinned SHA-256. VOICE_LOCAL_ASR=0 turns it off; VOICE_LOCAL_ASR_THREADS caps CPU threads. Recording still needs Soniox for speaker labels and never uses it.
  • Streaming and turns. The model is offline, so the stream re-decodes the open segment for partials, cuts long speech at 30 s on the quietest 50 ms frame, and ends a turn after about a second of silence following speech. The pause is heard by loudness alone (no language list, no second model).
  • Rewrite. Each closed segment is rewritten (filler, recognition mistakes, punctuation; same language, never translated) before it lands, on either the owner's connected Claude CLI or an OpenAI-compatible API of the deployment's own (DeepSeek by default). A failed or slow rewrite keeps the recognized text. The choice is a deployment-wide voice_dictation_settings row; dictation without a Soniox key stays off until someone chooses.
  • UI. A Local model page in the existing voice key dialog (and a row in Settings > Security) reusing the dialog, Button, Select and Field components. CLI route: pick a model alias every Claude CLI takes (Haiku first, Sonnet, Opus), since the choice applies to everyone. API route: address, key, and a round button that lists the API's models so nobody types a model name.
  • CLI model. A new dictation_polish model-call kind carries the rewrite through the same queue as chat. It names its model, which overrides the Agent's configured one on a Claude Runtime, over the model field model_invoke already has on main; this PR adds no wire or daemon change.

How it was verified

  • Focused tests: voice-runtime (SenseVoice stream, segments, endpoint detector), node-services (voice service incl. model download, model-call), TeamHub (voicedictation incl. SSRF refusal and model listing; the dictation settings service incl. which key goes to which address; error codes; the cached readiness probe), Web (voice key dialog, controls, Pocket dictation, i18n catalog).
  • Fast checks on the rebased branch: contracts:verify, check-repository, check-docs, check-web, check-node-services, check-teamhub, check-voice-runtime (typecheck, lint, build), check-scripts-fast, TeamHub lint-go incl. doc comments, go test of every non-integration package, the layout test, sqlc verification.
  • Real end to end in the Docker stack through Chrome: model download and load, dictation with a pause sending the turn and Linger replying, the CLI model picker (Haiku), saving a DeepSeek key, listing its models, and the rejected-key path against the real API.
  • Contracts regenerated from contracts/openapi/.
  • The browser run above predates the review follow-up. After rebuilding the Docker stack on the follow-up commit (with main's 00893 applied), checked through Chrome: listing models with the saved key at its own address, a changed address disabling save and asking for its own key, and the CLI list offering only Haiku, Sonnet and Opus. The save-with-another-address refusal is covered by tests only.
  • Not run here: check-installer, the Python packaging tests of check-desktop, and the migration history script (my test container lacks python3 and PowerShell). The Desktop bundle change (sherpa-onnx-node in RUNTIME_PACKAGES) is untested. Failing only in my Linux container and unrelated to this change: a timezone-dependent realtime.test.ts, and install and dev-computer script tests that need jq, curl or python3.

Boundary

  • Docs: docs/voice.md (dictation without a key, rewrite choices, model listing, pause ends a turn), docs/model-scheduling.md, and the AGENTS.md of voice-runtime and node-services. New env vars are in .env.example and scripts/env-inventory.json.
  • Compatibility: migration 00896 adds one table. New API fields and routes are additive, and an old Web client ignores local_dictation_supported. A Computer too old to decode model keeps the Runtime's default; a Runtime other than Claude keeps the Agent's model.
  • User message to provider_ready path: typed messages are untouched. A dictated turn adds one rewrite call before it is posted, bounded to about 10 s on the CLI and 8 s on an API, with the raw text as the fallback; the audio goes to no speech service.
  • Security: an API key is sealed with TEAMHUB_SECRET_ENCRYPTION_KEY (without it a key cannot be saved), checked against /models on save, never returned, and the saved key is probed, stored again or used for a model listing only at the address it was saved for. TeamHub accepts https only, with no credentials, query or fragment, dials only public addresses (checked again at connect time) and follows no redirect. Dictated text goes to the chosen API from the server running TeamHub. The choice is deployment-wide and any signed-in Human can change it, which docs/voice.md states; there is no owner-only gate, since a deployment has one Account and TeamHub has no separate owner role.

🤖 Generated with Claude Code

@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, 2 P2, 3 P3)

Scope: base main, merge base ef6f06d5, 1 commit (eef2e280), 96 files reviewed at the requested head. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. The review ran in a separate session.

Findings

P1

1. Saving the API settings with an empty key sends the saved key to any new address. apps/teamhub/internal/voice/dictation_settings.go:125-151

  • Problem: ListDictationModels correctly refuses to use the saved key unless config.BaseURL == baseURL, with the stated reason "otherwise a person could send it to a host of their choosing". SaveDictationAPI has no such check. When input.Key is empty and a ciphertext exists, it opens the saved key and runs s.dictationAPI.Probe(ctx, config) against the newly typed baseURL, which sends Authorization: Bearer <saved key> to <new base>/models (voicedictation/api.go:122-127).
  • Failure scenario: someone saves a DeepSeek key. Any signed-in Human then sends PUT /v0/voice-dictation-settings {"polish_source":"api","polish_api":{"base_url":"https://attacker.example","model":"x"}}. TeamHub sends the DeepSeek key to attacker.example. Any non-401/403/5xx answer also stores the attacker URL together with the old key. The Web page makes this easy to hit by accident: canSave in voice-local-model-page.tsx:158-164 accepts keySaved with any address, so changing the address to another provider without retyping the key leaks the old key to that provider.
  • Fix: in SaveDictationAPI, when the key is empty, reuse the saved key only if baseURL == existing.PolishApiBaseUrl.String; otherwise return ErrInvalidPolishAPI. Apply the same sameAddress rule to canSave on the Web page so it asks for a key once the address changes. Add a test for both cases.

P2

2. The settings logic in the voice service has no tests. apps/teamhub/internal/voice/dictation_settings.go

  • Problem: voicedictation/api_test.go covers the HTTP client: SSRF refusal and listing. The 238 lines that decide security and routing have no tests at all: key reuse on save, binding a listing to the saved address, opening a key sealed under another encryption key (Chosen=false), choosing API or CLI in PolishDictation, and the purpose and session checks. The same is true of the handlers in app/voice_dictation_settings.go. Finding 1 is the kind of bug those tests would have caught.
  • Fix: add table tests for SaveDictationAPI, ListDictationModels and PolishDictation with a fake DictationAPI that records which key went to which URL.

3. Any signed-in Human chooses where everyone's dictated text goes. apps/teamhub/internal/app/voice_dictation_settings.go:22-25

  • Problem: the row is deployment-wide, and the handler lets any session save it, "as for the voice provider keys". A Soniox key only changes which account pays. This setting changes the destination: once any user saves polish_source=api with an https URL they control and any key (the probe accepts a 404 or 200), every other user's dictated passages are POSTed to that URL. On a server shared by several tenants or teams, that is a quiet exfiltration path. The docs mention the setting is shared but not this consequence.
  • Fix: restrict saving to the deployment owner (internal/account/owner.go already has the concept), or make the API route per user. At least state the consequence in docs/voice.md.

P3

4. The voice policy now probes Node Services synchronously on every read. apps/teamhub/internal/app/voice_media_policy.go:37 → voice_local_asr.go:22

  • Once someone has chosen a rewrite, every getVoiceMediaPolicy and every dictation createVoiceSession makes an HTTP GET to /voice/health with a 1-second timeout. A slow or restarting Node Services adds up to 1 s to each page's policy read. The PR's critical-path note covers the rewrite call but not this round trip. A short cache of the state (a few seconds) would remove it.

5. One new table is built across two migrations. apps/teamhub/migrations/00893_voice_dictation_settings.sql, 00894_voice_dictation_polish_api.sql

  • Neither migration is on main yet, so 00894's ALTER TABLE can be folded into 00893's CREATE TABLE.

6. A CLI model picked from one person's catalog applies to everyone. apps/web/src/features/rooms/voice-control/voice-local-model-page.tsx:136-146

  • The options come from the saving user's own Computers, but PolishDictation runs on each dictating person's CLI. If someone picks a model id that only their Claude CLI offers, a colleague's claude --model <id> fails, and their dictation silently falls back to raw text with no sign why. Offer only the aliases (haiku, ...), or mention in the hint that the model must exist on every member's CLI.

Verified as fine

  • SSRF guard: NormalizeAPIBaseURL takes https only, refuses credentials, query, fragment and literal private IPs (voicedictation/api.go:47-57). The dialer's Control refuses non-public addresses after DNS resolution (api.go:80-91), which covers names that resolve inside the network and DNS rebinding. The custom http.Transport sets no Proxy, so no environment proxy bypasses the check. CheckRedirect returns ErrUseLastResponse. Response bodies are capped at 1 MiB.
  • The API key is never returned: the response has only key_saved (app/voice_dictation_settings.go:104-108). Polish errors report only the status, not the body (api.go:229-232).
  • CLI argument injection: the model must start with an alphanumeric character in TeamHub (voicedictation.go:69), node-services (model-call-http.ts MODEL_NAME), the contracts (node-services-internal/openapi.yaml, envelope.schema.json pattern) and the daemon (provider/model_invoke.go ValidModelName, checked in daemon/model_invoke.go:156). --model is added only when non-empty (claudeModelInvokeArgs).
  • Rolling deploy to Computers: model is sent only when runtimeType === "claude" and supportsModelInvokeModel (≥ 0.62.0, runner-connections.ts). apps/computer is bumped to 0.62.0. callId includes the model, so calls on different models are not deduplicated together (runtime-model-call.ts:607).
  • Polish failure paths: #rewrite falls back to the raw text on rejection, abort or a blank answer (sensevoice.ts #rewrite). The runtime aborts at 10.5 s (agent.ts), above TeamHub's 9 s CLI and 8 s API timeouts. Finals are emitted in segment order through the #emitting chain.
  • The internal polish route sits on the voice-runtime-authenticated group (routes_internal.go:111) and only serves chat_dictation sessions (dictation_settings.go:212). The CLI owner is the session's CreatedByActorID.
  • Model download: pinned revision and SHA-256, a .part file with Range resume and a fallback for hosts that ignore the range, rename only after the checksum passes (local-asr-model.ts). It starts only when no Soniox key is set and VOICE_LOCAL_ASR is not 0 (voice/service.ts apply). VOICE_LOCAL_ASR is in .env.example; VOICE_LOCAL_ASR_MODEL_DIR and VOICE_LOCAL_ASR_THREADS are in env-inventory.json.
  • Licenses: SpeakMore MIT text added; SenseVoice (FunASR model license) and sherpa-onnx (Apache-2.0) are noted in NOTICE.
  • No CJK outside the locale catalogs; no CJK in the commit message; no merge commits.

Not verified: contracts:generate && contracts:verify (no node_modules in this worktree); the Desktop bundling of sherpa-onnx-node's per-platform optional packages through RUNTIME_PACKAGES, which the PR also lists as untested; memory use with several concurrent local dictations (each LiveKit job process loads its own copy of the model, maxSessions = 16).

Process notes

  • The branch is one commit behind main (a3b6f44b), and main requires up-to-date branches, so it needs a rebase before merge.

CI

gh pr checks reports no checks on this branch, so nothing has run in CI. I ran no tests myself; the findings above come from reading the code.

Automated review by Claude Code


Automated review of eef2e28 by Claude Code.

@cnYui
cnYui force-pushed the feat/voice-local-dictation branch from eef2e28 to 59f338f Compare November 25, 2026 00:14

@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)

Scope: base main, merge base 9be58b70, 2 commits, 82 files. This is a follow-up on eef2e28. The branch was rebased since then, so I read the new 59f338fb commit, compared the rebased feature commit with the old one (git range-diff), and re-checked the whole merge-base diff for P0/P1 issues. I loaded the review skills from the repo's review recipe (coderbook, ponytail-review sections 1–3, karpathy-guidelines sections 2–3) and ran the review alone in a separate session.

Previous findings

  • P1: an empty key on save sent the saved key to a new address. Resolved. SaveDictationAPI now uses the saved key only through savedAPIKey, which returns ErrInvalidPolishAPI unless the normalized address matches the saved one (apps/teamhub/internal/voice/dictation_settings.go:166-172). ListDictationModels uses the same check. The Web page asks for a new key once the address changes: savedKeyApplies gates canSave and canListModels in voice-local-model-page.tsx. TestSaveDictationAPIUsesASavedKeyOnlyAtItsOwnAddress and TestListDictationModelsUsesASavedKeyOnlyAtItsOwnAddress cover it.
  • P2: the dictation settings service had no tests. Resolved. apps/teamhub/internal/voice/dictation_settings_test.go covers key reuse, address binding, refusal without a store write, CLI model validation, Chosen=false for a key that can't be decrypted, and routing by source. TestVoiceDictationErrorsKeepTheirCodes covers the error-code mapping.
  • P2: any signed-in user can redirect everyone's dictation. Partially resolved. There is still no gate. The author says a deployment has one Account and no owner role. docs/voice.md now states the risk and says leaving TEAMHUB_SECRET_ENCRYPTION_KEY unset turns the API route off, and the handler comment (voice_dictation_settings.go:24-27) says the same. I accept this as documented intent.
  • P3: a synchronous Node Services probe on every policy read. Resolved. The answer is cached for 3 s (voice_local_asr.go:23-45), and TestLocalDictationStateIsReusedForAFewSeconds covers it. A small new issue in the cache is below.
  • P3: two migrations for one new table. Resolved. There is now a single 00894_voice_dictation_settings.sql, numbered after main's latest (00893_transcript_only_captures.sql).
  • P3: CLI model options came from one person's Computer catalog. Resolved. The page now offers only the haiku/sonnet/opus aliases (cliModelAliases), isHostDefaultModelId is removed as dead code, and the docs match.

Findings

P3

  • apps/teamhub/internal/app/voice_local_asr.go:42: the cache stores a failure caused by the caller's own context. probeLocalDictation uses the request context, and any error becomes Unavailable, which is then cached for 3 s for every caller. Example: a client navigates away while the probe is in flight, so the probe fails on the cancelled context and Unavailable is cached. For the next 3 s, localDictationEnabled returns false to everyone. Policy reads hide local dictation, and createVoiceSession for a chat dictation fails with ErrProviderUnavailable (handlers_voice_media.go:62-68). Concurrent readers also wait on the mutex while a probe runs (up to 1 s). Fix: probe with context.WithoutCancel(ctx). localASRClient's 1 s timeout already bounds the call.

Verified as fine

  • The saved key never leaves its address. dictationAPIConfig returns the stored, already-normalized URL (dictation_settings.go:198-207), and both entry points compare it against NormalizeAPIBaseURL output.
  • SSRF controls: the address must be https with no userinfo, query or fragment, and a literal private IP is refused (voicedictation/api.go:47-58). The dialer's Control re-checks every resolved address, including CGNAT (api.go:83-94), and redirects are not followed (api.go:106). An error body is not echoed back (api.go:228-231).
  • The CLI model override reaches the Claude CLI as --model <alias> (local-daemon/internal/provider/model_invoke.go:755-757). Node Services validates the name against a regex that must start with a letter or digit (model-call-http.ts MODEL_NAME), so it can't be read as a flag. Only a Claude Runtime uses the override (runtime-model-call.ts:938-944), and the model is part of callId, so dedupe keys stay distinct.
  • Model download: pinned revision plus SHA-256 per file. A partial file is checked before it is renamed into place, and a host that ignores Range gets a full rewrite (node-services/src/voice/local-asr-model.ts:106-160).
  • Migration: one table, CHECK constraints keep the API row complete, and goose Down drops it.
  • No CJK outside the locale catalogs, and no CJK in commit messages. No merge commits.

Process notes

  • 59f338fb fix(voice): address review of local dictation only patches 8ad60ec4. main takes rebase merges, so squash it into the feature commit before merging.
  • The branch is up to date with main. Merge state is BLOCKED because CI hasn't run (see below).

CI

  • The CI workflow for 59f338fb (and for eef2e28 before it) shows action_required: a maintainer has to approve the workflow run, so no checks have run on this head.
  • I ran these locally: go test -count=1 ./internal/voicedictation/ ./internal/voice/ -run 'Dictation|API|Normalize|Model|Polish' and go test -count=1 ./internal/app/ -run 'Dictation|LocalASR|LocalDictation'. All passed.
  • Not run here: Web, node-services and voice-runtime tests, and the Desktop native bundle with sherpa-onnx-node, which the PR also lists as untested.

Automated review by Claude Code


Automated review of 59f338f by Claude Code.

@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)

Scope: follow-up on 59f338f, reviewing head de3a8db against base main (merge base 9be58b7). I read the incremental diff (2 files) and spot-checked the whole PR's merge-base diff (3 commits, 82 files) for P0/P1 risk. The helper skills (coderbook, ponytail-review, karpathy-guidelines) were not loaded for this follow-up; I worked from the linger-pr-review checklist directly. The review ran in a separate session.

Previous findings

  • P3 A failed probe from a cancelled request was cached for 3 s: Resolved. apps/teamhub/internal/app/voice_local_asr.go:44 now probes with context.WithoutCancel(ctx), and the 1 s localASRClient.Timeout (voice_local_asr.go:18) still limits how long the probe can take. TestLocalDictationStateIgnoresTheCallersCancellation (voice_local_asr_test.go:70) covers this. Without the fix, http.Client.Do fails on the cancelled context and the probe caches Unavailable, so the test does fail on the old code.

Findings

None.

Verified as fine

  • Readiness cache: the probe runs under a.localASR.mu, so at most one probe is in flight at a time. Each caller waits no more than about 1 s (the client timeout), and the result is cached for 3 s (voice_local_asr.go:36-47).
  • SSRF guard on the deployment's API route:
    • NormalizeAPIBaseURL accepts only https URLs with no userinfo, query, fragment or literal private address (apps/teamhub/internal/voicedictation/api.go:47-58).
    • The dialer's Control hook checks every resolved address against publicAddress, which covers loopback, private, link-local, multicast, unspecified and 100.64/10 (api.go:72-92, api.go:100).
    • Redirects are refused (api.go:107). The custom Transport leaves Proxy unset, so no environment proxy can bypass the dial check.
  • The API error path does not echo the response body, which may contain the prompt; it reports only the status (api.go:225-228). Response bodies are capped at 1 MiB (api.go:131, api.go:221).
  • CLI model names are checked against an anchored regex that requires a letter or digit first, so a model name cannot be read as a CLI flag (voicedictation.go:69).
  • Rewrite calls share one key per session, model and text digest (voicedictation.go:88), so a retried passage joins the call already running instead of starting another one.
  • No CJK appears in changed files outside the locale catalogs or in any commit message. There are no merge commits.

Process notes

  • 59f338f ("address review of local dictation") and de3a8db (the cancellation fix) only patch 8ad60ec. Squash them into it before the rebase merge.
  • mergeStateStatus is BLOCKED, and gh pr checks reports no checks for the branch, so CI still needs to run on this head.

CI

  • No checks are reported on the PR at de3a8db.
  • I ran go test -count=1 -run 'TestLocalDictation' ./internal/app/ in apps/teamhub locally, and it passed.
  • I did not run anything else. As the PR body notes, the Desktop bundle change (sherpa-onnx-node in RUNTIME_PACKAGES) is untested.

Automated review by Claude Code


Automated review of de3a8db by Claude Code.

@muterC

muterC commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

I benchmarked this branch (merged onto current main) with the int8 SenseVoiceSmall model and sherpa-onnx-node 2.0.3, and ran 10-minute and 3-hour dictation and meeting simulations. Results and suggestions below.

Setup. Apple M5 (10 cores, 16 GB), CPU decoding. Test speech was synthesized with macOS voices: Chinese, English, and a 6-speaker meeting with speaker changes and 0.3–2 s gaps. Clean synthetic audio is a best case, so real microphones will do worse. The simulations feed 20 ms frames in real time, as livekit-worker.ts does, into this PR's SenseVoiceASRStream and log latency, CPU, memory and the input backlog.

1. Speed: CPU only, and fast enough

Decode time for one clip, best of 3 rounds (ms):

3 s 5 s 10 s 30 s
int8, 1 thread 91 135 264 804
int8, 4 threads (this PR's default) 37 71 137 397
int8, provider: "coreml" 55 102 175 514
  • CoreML gives no speedup. provider: "coreml" uses the same CPU time per decode as cpu, and GPU utilisation stays at 0%. This holds for the fp32 model too. The npm build effectively runs on the CPU only, and with int8 it also adds 3–9 s to load time.
  • int8 is enough. int8 and fp32 transcripts were identical apart from the odd comma.
  • Resource use. Memory is about 400–600 MB with 4 threads and the model loads in under 1 s.

2. Accuracy

These are error rates for decoding each utterance on its own. Part of each number is number formatting: 三 becomes 3, "ten" becomes 10.

  • Chinese. Dictation CER is 2.1%. The multi-speaker meeting CER is 5.6%. Punctuation and inverse text normalization work well.
  • English. WER is 11.5% over 16 utterances. Real misses include "into dictation" → "in Ad" and "rewrite" → "right".
  • Product names. They are spelled by sound in both languages: Linger → "lineer", TeamHub → "teamh", Soniox → "sonny". The rewrite or a homophone/hotword rule (HomophoneReplacerConfig) is needed for these.

3. Bug: the loudness endpoint cuts speech mid-sentence, and SenseVoice then drops text

EndpointDetector takes the 20% quantile of the last 10 s as the noise floor. In dense speech with few pauses, that quantile is speech, so speech counts as silence and a "pause" fires mid-sentence. In the meeting audio it cut at 4.3 s and at 10.4 s, where the 100 ms RMS around both cuts never drops below 0.09.

SenseVoice then loses most of a segment that starts mid-sentence or spans two speakers:

  • The 10.4–20.4 s segment held "在我的电脑上跑得挺流畅的。那长时间录音的情况测过了吗?我比较担心说久了会越来越卡。" and decoded to only "在我近挺畅的。"
  • Each of the two utterances in that segment decodes correctly on its own.
  • A 3 s mid-sentence fragment was even recognised as Cantonese.

Over the 10-minute meeting, the stream's text differed from per-utterance decoding by 6.4%. For single-speaker dictation the difference was only 0.6%, so meetings are where this hurts.

4. Suggested fix: segment on the Silero VAD

The voice workers already install Silero through @livekit/local-inference, the same model Live uses in voice-activity.ts. It costs about 0.17% of one core: 1.1 s of CPU for 10 minutes of audio.

With segmentation driven by Silero:

  • A 400 ms pause after speech closes the segment, without ending the turn.
  • About 1 s of silence still ends the turn with utterance_end, as now.
  • Audio with no detected speech is never decoded.
  • The 30 s quietest-frame cut stays as the fallback for unbroken speech.

Results on the same meeting:

loudness endpoint Silero VAD
difference from per-utterance decoding 6.4% **3.2%**¹
whole sentences lost several none
longest segment 14–16 s 8–11 s
CPU, one core = 100% ~30% ~25–30%

¹ Most of the remaining 3.2% is a scoring artifact: two speakers less than 400 ms apart share a segment and are both transcribed correctly.

5. Long sessions do not accumulate load

  • 10 minutes in real time.
    • Continuous dictation with no pauses, worst case for the 30 s cuts: p95 partial latency about 400 ms, single-core CPU about 70–85%, RSS 430–550 MB, backlog under 0.5 s.
    • Meeting: p95 about 100 ms and CPU about 25–30%.
    • Minute 10 looks the same as minute 1.
  • Under heavy load. When another process drove the load average to 40–53 during one run, the input backlog stayed at 0. Partials slowed to 1.5–2 s and then recovered.
  • 3-hour meeting at 4× speed. This was the recording-mode stream described in section 6.
    • The 0–1 h, 1–2 h and 2–3 h windows look the same: p50 partial lag about 57 ms, longest segment 11.8 s, RSS 180–450 MB, JS heap 8–51 MB, and no sendPCM call above 274 ms.
    • Progress events: 3,477, never moving backwards, ending exactly at the end of the audio.
    • The same 10-minute audio was looped 18 times. Every loop transcribed to 2,631–2,635 characters, with no drift across loops.

6. Meetings can run on the local model too

This PR keeps recording on Soniox. Making meetings work locally, without speaker labels, took three small changes:

  • voice-runtime. A recording mode for SenseVoiceASRStream. A pause only closes a segment and never emits utterance_end, which forwardEvents rejects for recordings. A progress event with committedThroughMs follows each final, and silence is closed about once a second without a decode, so coverage keeps advancing. The last 500 ms of a silent segment carries into the next one, so a word's onset that the VAD has not judged yet is not dropped. No rewrite runs.
  • node-services. When the local model is ready, run the recorder worker beside asr. It only encodes audio and needs no key.
  • TeamHub. Set voice_media_supported and accept hardware_control sessions when the model is ready and both workers run.

Trade-offs:

  • No backfill. Archive recovery remains Soniox-only, so a gap from a worker restart stays a gap.
  • Coupled to the rewrite choice. Local meetings currently wait for the dictation rewrite choice. The Web client reads voice_media_supported as "dictation available" too, so offering meetings without the choice would show a dictation button that TeamHub then refuses. Suggestion 3 removes this coupling.

Suggestions

  1. Replace the loudness EndpointDetector with Silero VAD segmentation (section 4). This is the main accuracy fix, and it also makes each decode cheaper.

  2. Local meetings (section 6) could go in a follow-up PR on top of this one.

  3. Drop the real-time rewrite from this PR and decouple local ASR from it. Local dictation and meetings should turn on as soon as the model is ready, with no rewrite choice to make first. Reasons:

    • Parallelism. A local deployment has little to spare. The machine already runs the ASR worker, the recorder and the Agent's own Runtime work. A rewrite on the owner's Claude CLI per closed segment adds a model call every few seconds, through the same model-call queue as chat.
    • Latency. Each final waits for its rewrite, up to about 10 s, before it lands.
    • Need. SenseVoice already writes punctuation and numbers.
    • Coupling. It also removes the coupling described in section 6.

    Concretely, that means dropping:

    • the dictation_polish model-call kind;
    • the CLI/API rewrite settings and their table and migration;
    • the API key storage, the SSRF checks and the model listing;
    • the rewrite page in the voice key dialog.

    A rewrite can come back later as a separate feature. It could run once per finished turn or meeting rather than per segment, for example inside the meeting summary, which already runs on the Agent's model.

  4. sherpa-onnx-node 2.0.3 is a required dependency. feat(voice): transcribe dictation locally without a Soniox key #432 pinned 1.12.14 because 2.x needs a newer libstdc++ than Ubuntu 22.04 ships. Please check Linux images and the Desktop bundle, or make it optional with a clean fallback.

  5. Download on first use. Today every deployment without a Soniox key fetches 239 MB at startup, including ones that never dictate.

  6. English and product names need a hotword/homophone list (HomophoneReplacerConfig), or the later non-real-time rewrite from suggestion 3. English WER is about 11% even on clean speech.

  7. The 1.2 s partial-refresh floor could come down. With VAD-sized segments, a 3–5 s decode takes 40–70 ms on 4 threads, so 300–500 ms refreshes are affordable.

The Silero segmentation and the local-meeting change are two commits that apply on top of the current head of this branch. They include unit tests: phrase and turn cuts, never decoding silence, recording progress, and silence advancing progress. I'm happy to open them as a stacked PR.

@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), but it can't land as is: see Process notes.

Scope: follow-up on de3a8db. Base main, merge base 7fab8a51, 4 commits on the branch. The only new commit since the previous review is the merge commit 53977948, which brings in main; I read its conflict resolution with git show --remerge-diff (5 files). Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Previous findings

The previous review (de3a8db) had no findings.

Findings

None.

Verified as fine

  • Migration number. main added 00894_room_handoff_reports.sql, so the merge renames this PR's migration from 00894_voice_dictation_settings.sql to apps/teamhub/migrations/00895_voice_dictation_settings.sql. The content is unchanged (similarity 100%). go test ./apps/teamhub/migrations (TestMigrationVersionsAreUnique) passes at this head.
  • Dialog copy conflicts. main's copy trim (d33fdf1f/7fab8a51) removed the ModalDialog description and these messages: chooseProvider, sonioxDetail, xaiDetail and composioDialogDescription. The merge follows main and also drops the PR's chooseProviderOrLocal and localDialogDescription. git grep finds no remaining reference to any removed message in apps/web/src, and the English catalogs match zh-CN.json.
  • voiceKey.keyHint. The merge keeps it in voice-key.messages.ts:31 and zh-CN.json. It is still used at apps/web/src/features/rooms/voice-control/voice-local-model-page.tsx:260.
  • Local model row in Settings. localModel, localModelDetail and chooseModel survive the merge and are used at apps/web/src/features/settings/api-keys-settings.tsx:78-81.
  • Rest of the PR. I re-checked the PR against the merge base for P0/P1 problems and found nothing new. The TeamHub voicedictation and voice packages pass their tests at this head.

Process notes

  • Merge commit 53977948 ("fix(voice): reconcile local dictation with main"). main only accepts rebase merges, and those drop merge commits. Two things live only in this merge commit: the conflict resolution in the four Web files, and the migration rename from 00894 to 00895. If the commits were replayed onto main, 8ad60ec4 would conflict in those Web files and would bring back 00894_voice_dictation_settings.sql, which clashes with main's 00894_room_handoff_reports.sql. Please rebase onto main instead of merging: resolve the same conflicts in the original commits, and give the migration number 00895 in 8ad60ec4.
  • 59f338fb and de3a8db1 are follow-up review fixes to 8ad60ec4. Consider squashing them in during the same rebase.

CI

GitHub reports no checks for head 53977948, so nothing has run on the merged state. I ran these myself: go test -count=1 ./internal/voicedictation/ ./internal/voice/ ./migrations/ in apps/teamhub, and all passed. Web typecheck and tests did not run, because this worktree has no node_modules. The merge state is BLOCKED.

Automated review by Claude Code


Automated review of 5397794 by Claude Code.

@cnYui
cnYui force-pushed the feat/voice-local-dictation branch from 5397794 to aad11fa Compare November 26, 2026 11:21

@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 P0, 0 P1, 0 P2, 0 P3). CI has not run on this head, and the branch must be rebased first (see Process notes).

Scope: follow-up on 5397794. Base main, merge base 29ad855e. One commit (aad11fa5) and 81 files reviewed at aad11fa5. Helper skill loaded: ponytail-review (sections 1–3). coderbook and karpathy-guidelines were not loaded for this follow-up. Their criteria were applied from the review checklist. Ran in a separate session.

Previous findings

The previous review (5397794) had no findings, so nothing carries over.

What changed since 5397794

The branch was force-pushed. Four commits were squashed into one and rebased onto 29ad855e. I compared the old PR patch (merge-base..5397794) with the new one (29ad855e..aad11fa5), ignoring index and hunk headers. They differ in only two places:

  • The migration is renamed 00895_voice_dictation_settings.sql → 00896_voice_dictation_settings.sql. main now has 00895_runtime_local_computers.sql, so the rename is required and correct.
  • Context lines in docs/model-scheduling.md come from main. The PR's own lines there are unchanged.

Findings

None.

Verified as fine

  • Migration. apps/teamhub/migrations/00896_voice_dictation_settings.sql is a forward-only single table: a singleton row with a CHECK constraint. The API source requires the base URL, the model and the sealed key (voice_dictation_api_complete). Down drops the table. It does not collide with main's highest migration, 00895.
  • SSRF guard on the rewrite API.
    • apps/teamhub/internal/voicedictation/api.go:49-53 rejects non-https URLs, userinfo, query, fragment and literal private hosts.
    • refusePrivateAddress (api.go:83) runs as net.Dialer.Control on every connection, after DNS resolution. This covers names that resolve to private addresses and DNS rebinding.
    • publicAddress (api.go:73) unmaps v4-in-v6 addresses and excludes CGNAT 100.64.0.0/10.
    • The transport sets no Proxy, so HTTPS_PROXY is not used and cannot bypass the dial check.
    • CheckRedirect returns ErrUseLastResponse (api.go:108), so no redirect is followed.
  • Native module loading in the flattened Desktop bundle.
    • apps/voice-runtime/src/sensevoice-recognizer.ts:33,59 loads sherpa-onnx-node through createRequire, which esbuild leaves unbundled.
    • On main, build-native-runtime.mjs adds RUNTIME_PACKAGES to the deployed closure roots, so listing the package there is the right mechanism.
    • The per-platform binaries are optional dependencies of sherpa-onnx-node@2.0.3 in pnpm-lock.yaml. The deploy step passes --os/--cpu/--libc, so it selects the matching one.
    • Unverified: an actual Desktop build. The PR body states this too.
  • Rest of the PR. Contracts, model-call kind, Web UI and docs are byte-identical to what was reviewed at 5397794.

Process notes

  • Rebase required: conflict with main. mergeStateStatus is DIRTY. git merge-tree origin/main HEAD reports a content conflict in apps/desktop/scripts/build-native-runtime.mjs. main (19cdc336, "flatten node-services bundle") changed the list to export const RUNTIME_PACKAGES = ["@livekit/local-inference"] and dropped word-extractor, which is now bundled. When resolving:
    • Keep "sherpa-onnx-node" in that exported list. Without it, Desktop ships without the native addon and local dictation fails at require.
    • Do not re-add word-extractor.
    • Update apps/desktop/src/main/build-native-runtime.test.ts:392, which on main asserts RUNTIME_PACKAGES equals ["@livekit/local-inference"]. Otherwise check-desktop fails.
  • History is a single conventional commit, with no merge or fixup commits.

CI

No checks have run on aad11fa5: the GitHub check-runs API reports 0 runs. GitHub creates no merge ref while the PR conflicts with main, so pull_request workflows have not started. Nothing in this PR has CI evidence at this head. I ran no tests myself: the PR's code is unchanged since the last review apart from the migration rename.

Automated review by Claude Code


Automated review of aad11fa by Claude Code.

With no Soniox key, chat and Pocket notes dictation now runs on the
SenseVoiceSmall int8 model (sherpa-onnx), ported from SpeakMore (MIT).
Node Services downloads it once into AGENT_HOME/models (Hugging Face, or
hf-mirror.com first in the cn region) with pinned checksums, and the voice
worker runs it on the CPU. The model is offline, so the stream re-decodes the
open segment for partials, cuts long speech at 30 s at the quietest frame, and
ends a turn after about a second of silence by loudness alone.

Each closed segment is rewritten (filler, recognition mistakes, punctuation)
before it lands, on either the owner's connected Claude CLI or an
OpenAI-compatible API of the deployment's own, such as DeepSeek. The choice is
a deployment-wide voice_dictation_settings row; an API key is sealed with
TEAMHUB_SECRET_ENCRYPTION_KEY and checked against /models on save. TeamHub
connects only to public addresses and follows no redirect. A failed or slow
rewrite keeps the recognized text.

The Local model page of the voice key dialog (and a row in Settings >
Security) offers both routes; for the API route a round button lists the
API's models, using the saved key only for the address it was saved for. The
Claude catalog picks the CLI model, Haiku by default.

To pass that model to the CLI, model_invoke gains an optional model sent only
to Computers from 0.62.0, which accept it as --model; older Computers keep
the Runtime's default. A new dictation_polish model-call kind carries the
rewrite through the same queue as chat.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cnYui
cnYui force-pushed the feat/voice-local-dictation branch from aad11fa to e7718d6 Compare November 26, 2026 11:37

@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 P0, 0 P1, 0 P2, 0 P3)

Scope: follow-up on aad11fa. Base main, merge-base 19cdc336; 1 commit (e7718d62) and 82 files reviewed. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Previous findings

The previous review (aad11fa) had no findings. Since then the branch was rebased onto a newer main. git range-diff shows the only change outside the rebase is the conflict resolution in apps/desktop/scripts/build-native-runtime.mjs and its test. main has dropped word-extractor and now exports RUNTIME_PACKAGES. The PR now adds sherpa-onnx-node to the exported list, and apps/desktop/src/main/build-native-runtime.test.ts asserts the new list. The resolution is correct.

Findings

None.

Verified as fine

The whole PR was re-checked against the merge base, not only the delta.

  • SSRF guard. NormalizeAPIBaseURL (apps/teamhub/internal/voicedictation/api.go:47) accepts https only and rejects credentials, query, fragment and literal private IPs. The dialer's Control: refusePrivateAddress (api.go:83) checks the resolved address on every connection, so a public name that resolves to a private address is refused too (this also blocks DNS rebinding). The transport sets no Proxy, and CheckRedirect returns ErrUseLastResponse. Response bodies are capped at 1 MiB.
  • Saved key cannot be exfiltrated. savedAPIKey (apps/teamhub/internal/voice/dictation_settings.go:146) opens the stored key only when the requested base URL equals the saved one. Both the save path with an empty key and ListDictationModels go through it. The key is sealed with the secret box before storage and never returned; voiceDictationSettings only sets KeySaved.
  • Key storage misconfiguration. With no TEAMHUB_SECRET_ENCRYPTION_KEY, saving is refused with ErrDictationKeyStorage. A key sealed under another encryption key makes Chosen=false (dictation_settings.go:87-91), which keeps local dictation off instead of failing at polish time.
  • Session gating. The internal dictation-polish route resolves the session and refuses any purpose other than chat_dictation. The CLI polish runs as the session creator (dictation_settings.go:243). createVoiceSession only falls back to the local model for chat_dictation, and only once settings are chosen and the model is ready (handlers_voice_media.go:58-68). Recording still requires Soniox (apps/voice-runtime/src/agent.ts throws otherwise).
  • CLI model argument. ValidModel requires the first character to be alphanumeric, so the name can never be read as a flag. The --model field is the one main already gates to Computer 0.62.0 or later (apps/node-services/src/agent/runner-gateway/local-computer-management.ts:75). This PR adds no wire or daemon change, as the body says. In runtime-model-call.ts, wireModel uses call.model only when the runtime type is claude. callId now includes the model, so calls with different models do not dedupe into each other.
  • Model download. The download is pinned to a revision with SHA-256 per file. It writes to .part and renames only after the checksum passes. The completion marker is written after every file is verified (apps/node-services/src/voice/local-asr-model.ts:92). A failed download is retried by the periodic reconcile poll (apps/node-services/src/voice/service.ts:435). Re-entry is guarded by localInstalling. When a Soniox key exists the model is never downloaded.
  • Worker env isolation. VOICE_LOCAL_ASR_MODEL_DIR is blanked alongside the provider keys for every spawned worker, so only the ASR worker sees it. localAsrConfig returns undefined when SONIOX_API_KEY is set.
  • Readiness probe cost. localDictationState caches the Node Services /voice/health answer for 3 s, with a 1 s client timeout and WithoutCancel. The page-load policy therefore cannot be held up longer than one bounded probe.
  • Migration. 00896 is the next number after main's 00895. It is a single-row table, with a CHECK that makes the API source require all three API fields.
  • Repo conventions. Added CJK appears only in apps/web/src/i18n/locales/zh-CN.json. The new env vars are in .env.example and scripts/env-inventory.json. The generated contracts come with changes to contracts/openapi/. docs/voice.md, docs/model-scheduling.md and the affected AGENTS.md files are updated.

Process notes

  • main is 1 commit ahead of this head. The branch needs a rebase before it can merge (merge state: BLOCKED).
  • No CI check runs are reported for e7718d62 yet. Confirm CI is green before merging.
  • No merge commits and no fixup commits. The commit author is linked (cnYui).

CI

No checks are reported for this head (gh pr checks returns none; the commit's check-runs total is 0). I ran no tests myself. Nothing in the delta since aad11fa called for one beyond the desktop runtime-package test, whose updated assertion matches the resolved list.

Automated review by Claude Code


Automated review of e7718d6 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