diff --git a/.env.example b/.env.example index a2c1bfc..c1bb9c8 100644 --- a/.env.example +++ b/.env.example @@ -23,9 +23,17 @@ HERMEVEN_DB_PATH=./data/hermeven.sqlite # Read the real value from Diagnostics -> "Page origin" in the phone page. HERMEVEN_ALLOWED_ORIGINS= -# --- Speech-to-text (optional; typed questions work without it) -------------- -# "none" or "openai-compatible" (any server with POST {base}/audio/transcriptions). -STT_PROVIDER=none +# --- Speech-to-text ----------------------------------------------------------- +# "builtin" (default): Whisper runs inside the bridge on the CPU. No account, and recordings +# never leave the bridge host. Model files (about 80 MB) are downloaded on first start. +# "openai-compatible": any server with POST {base}/audio/transcriptions. +# "none": typed questions only. +STT_PROVIDER=builtin +# STT_MODEL=onnx-community/whisper-base # or whisper-tiny (faster), whisper-base.en (English only) +# STT_DTYPE=q8 +# STT_CACHE_DIR=./data/models +# +# For STT_PROVIDER=openai-compatible: # STT_BASE_URL=https://stt.example/v1 # STT_API_KEY=replace-with-your-stt-key # STT_MODEL=whisper-1 diff --git a/.gitignore b/.gitignore index ebbf5d7..78bd2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ coverage/ tests/simulator/.artifacts/ tests/real-hermes/.artifacts/ dist-manifest/ +tests/real-stt/.cache/ diff --git a/README.md b/README.md index b3b5352..395931c 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,11 @@ small bridge between the two. | Path | State | |---|---| | Client, bridge and contract | Implemented. | -| Automated tests with fakes (122) | Passing. | +| Automated tests with fakes (130) | Passing. | | Client in Even's official simulator | Passing (6 scenarios). Simulator only. | | Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. | -| Real speech-to-text | **Not run.** No provider was configured. | +| Built-in speech-to-text (Whisper, in the bridge) | Passing (4 scenarios) on a real speech recording. Not yet on audio from the glasses. | +| Running on a droplet | **Not run.** See `docs/deploy-droplet.md`. | | Real model, real tools, approval flow | **Not run.** | | Physical G2, ring, locked-phone use, battery | **Not run.** See `docs/device-test-plan.md`. | @@ -28,7 +29,7 @@ thing to test on a device and it is not known to work. ``` G2 <-Bluetooth-> Even phone app (WebView: apps/even-client) | HTTPS + device credential - services/bridge --> speech-to-text endpoint you choose + services/bridge (speech-to-text built in: Whisper on the CPU) | your Hermes API server ``` @@ -75,6 +76,7 @@ npm run typecheck npm test # unit and integration, fakes only npm run test:simulator # opens Even's simulator window npm run test:real-hermes # real `hermes gateway` in a throwaway home, stub model +npm run test:real-stt # the built-in Whisper model on a real speech recording ``` What each suite does and does not show is in `docs/test-evidence.md`. @@ -89,6 +91,7 @@ What each suite does and does not show is in `docs/test-evidence.md`. | `docs/bridge-api.md` | The bridge contract. | | `docs/security.md` | Threat model, controls, known gaps. | | `docs/setup.md` | Running, building, operating. | +| `docs/deploy-droplet.md` | Running the bridge on a DigitalOcean droplet. Written, not yet run. | | `docs/device-test-plan.md` | The physical-device checklist. Not yet run. | | `docs/test-evidence.md` | Commands run and their real results. | | `docs/decisions/` | Decision records. | diff --git a/deploy/Caddyfile.example b/deploy/Caddyfile.example new file mode 100644 index 0000000..a23db47 --- /dev/null +++ b/deploy/Caddyfile.example @@ -0,0 +1,10 @@ +# Caddy terminates TLS (certificates are obtained automatically) and forwards to the bridge +# on loopback. Replace the hostname. Example only: not yet run on a droplet. +bridge.example.com { + encode zstd gzip + # Audio uploads are at most about 1 MB at the default 30 s cap. + request_body { + max_size 2MB + } + reverse_proxy 127.0.0.1:8787 +} diff --git a/deploy/bridge.env.example b/deploy/bridge.env.example new file mode 100644 index 0000000..3120fdd --- /dev/null +++ b/deploy/bridge.env.example @@ -0,0 +1,17 @@ +# /etc/hermeven/bridge.env on the droplet (chmod 600, owned by the hermeven user). +HERMES_BASE_URL=http://127.0.0.1:8642 +HERMES_API_KEY=replace-with-the-hermes-api-server-key +HERMES_PROFILE_LABEL=default + +HERMEVEN_HOST=127.0.0.1 +HERMEVEN_PORT=8787 +# Caddy is in front, so the client address comes from its forwarded header. +HERMEVEN_TRUST_PROXY=true +HERMEVEN_DB_PATH=/var/lib/hermeven/hermeven.sqlite +# Read the real value from the phone page: Diagnostics -> "Page origin". +HERMEVEN_ALLOWED_ORIGINS= + +# Built-in speech-to-text (the default). Model files are downloaded once into this directory. +STT_PROVIDER=builtin +STT_MODEL=onnx-community/whisper-base +STT_CACHE_DIR=/var/lib/hermeven/models diff --git a/deploy/hermeven-bridge.service b/deploy/hermeven-bridge.service new file mode 100644 index 0000000..276f510 --- /dev/null +++ b/deploy/hermeven-bridge.service @@ -0,0 +1,35 @@ +# systemd unit for the Hermeven bridge. Example only: it has not been run on a droplet yet. +# Install: copy to /etc/systemd/system/, adjust paths, then +# systemctl daemon-reload && systemctl enable --now hermeven-bridge +[Unit] +Description=Hermeven bridge +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=hermeven +Group=hermeven +WorkingDirectory=/opt/hermeven +# Secrets live here, mode 600, owned by the service user. Never in the repository. +Environment=HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env +ExecStart=/usr/bin/npm run --silent bridge +Restart=on-failure +RestartSec=3 +# In-flight turns are recovered from SQLite on the next start. +TimeoutStopSec=20 + +# Hardening +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ProtectHome=true +ReadWritePaths=/var/lib/hermeven +ProtectKernelTunables=true +ProtectControlGroups=true +RestrictSUIDSGID=true +# The speech model needs roughly 0.8 GB resident; leave headroom. +MemoryMax=1500M + +[Install] +WantedBy=multi-user.target diff --git a/docs/architecture.md b/docs/architecture.md index c0d59af..6f9fee2 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6,7 +6,7 @@ G2 mic / touch / HUD Even phone app -- WebView running apps/even-client (public Even Hub SDK) | HTTPS, device credential, polling services/bridge (Fastify + SQLite) - |-- STT adapter --> an OpenAI-compatible transcription endpoint you choose + |-- STT adapter --> built-in Whisper (in process), or an external endpoint |-- Hermes adapter --> Hermes API server (Runs API) for one configured profile ``` diff --git a/docs/compatibility.md b/docs/compatibility.md index 5e45329..d350f0d 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -39,6 +39,8 @@ exactly in `apps/even-client/package.json`. | Vite / Vitest | 8.3.8 / 5.1.1 | | Fastify / @fastify/cors | 5.12.8 / 11.4.3 | | better-sqlite3 | 13.2.0 | +| @huggingface/transformers (ONNX Runtime 1.30.0) | 4.3.2 | +| Speech model | `onnx-community/whisper-base`, `q8` | | @sinclair/typebox | 0.34.52 | | pino | 10.4.0 | diff --git a/docs/deploy-droplet.md b/docs/deploy-droplet.md new file mode 100644 index 0000000..776e869 --- /dev/null +++ b/docs/deploy-droplet.md @@ -0,0 +1,89 @@ +# Running the bridge on a DigitalOcean droplet + +**Status: written, not run.** These steps have not been executed on a droplet. The bridge, the +built-in speech model and the Hermes adapter have only been run on the development desktop. +Creating the droplet, pointing DNS at it and starting services are Dan's actions. + +## What runs where + +``` +phone (Even app) --HTTPS--> Caddy :443 --> bridge 127.0.0.1:8787 --> Hermes 127.0.0.1:8642 + | + built-in Whisper (in the bridge process) +``` + +The bridge listens on loopback only. Caddy is the only thing exposed, and it provides the +certificate. Speech is transcribed inside the bridge, so recordings never leave the droplet. + +Hermes can run on the same droplet (shown above) or elsewhere; if elsewhere, `HERMES_BASE_URL` +must be `https://`. + +## Sizing + +Measured on the development desktop (Intel i7-13850HX), bridge with `whisper-base`, 8-bit +weights: + +| Measurement | Value | +|---|---| +| Memory after loading the model | about 0.5 GB | +| Memory after transcribing | about 0.8 GB | +| 11 s of speech, process pinned to one core | about 1.7 s | +| Same, `whisper-tiny` | about 1.2 s, about 0.6 GB | +| Model download on first start | about 80 MB (`base`), cached afterwards | +| Longest pause of the bridge's event loop while transcribing | about 0.4 s | + +Pinning to one core made no difference to speed, so extra cores will not help; a single droplet +vCPU is the relevant unit. **A shared droplet vCPU is slower than that desktop core by an amount +that has not been measured.** If it were three times slower, 11 s of speech would take about 5 s, +well inside the 30 s deadline. + +Suggested starting point, to be confirmed by measuring on the droplet: **2 GB RAM, 1 to 2 vCPU** +for the bridge alone. 1 GB is likely too tight alongside the OS. If Hermes shares the droplet, +add whatever Hermes needs; that was not measured. + +If transcription is too slow on the droplet, set `STT_MODEL=onnx-community/whisper-tiny` +(faster, less accurate) or, for English only, `onnx-community/whisper-base.en`. + +## Steps + +1. **Droplet and DNS.** Ubuntu LTS. Point a hostname at it (for example `bridge.example.com`). + Firewall: allow 22, 80 and 443 only. +2. **Packages.** Node.js 22.13 or later, git, Caddy. +3. **User and directories.** + ```sh + useradd --system --home /opt/hermeven --shell /usr/sbin/nologin hermeven + mkdir -p /opt/hermeven /var/lib/hermeven /etc/hermeven + chown hermeven:hermeven /var/lib/hermeven + ``` +4. **Code.** Clone the repository into `/opt/hermeven`, then `npm ci`. (The dev dependencies are + needed: the bridge runs through `tsx`.) +5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it + in, `chmod 600`, `chown hermeven`. +6. **Hermes.** Enable its API server with a key, bound to `127.0.0.1`. Use a read-only or test + profile first. +7. **Service.** Copy `deploy/hermeven-bridge.service` to `/etc/systemd/system/`, then + `systemctl daemon-reload && systemctl enable --now hermeven-bridge`. Watch + `journalctl -u hermeven-bridge -f` for `stt.ready` (the first start downloads the model). +8. **TLS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, reload + Caddy, then check `curl https://bridge.example.com/healthz`. +9. **App build.** On your own machine: + `HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`. +10. **Pair.** On the droplet, as the service user with the same environment: + ```sh + sudo -u hermeven HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- pair + ``` +11. **Origin.** Open the phone page, read Diagnostics, "Page origin", put it in + `HERMEVEN_ALLOWED_ORIGINS`, restart the service. + +## Things to check on the droplet and write down + +- Time from `stt.loading` to `stt.ready`, and memory of the service after a few questions. +- `transcribe_ms` for a few real questions (the phone page shows it per question). +- That `curl http://:8787/healthz` from outside **fails** (bridge not exposed). +- That the unit's hardening options do not stop the model loading. `ProtectSystem=strict` and + `MemoryMax` in particular are untested with ONNX Runtime. + +## Not covered yet + +Backups of `/var/lib/hermeven`, log rotation, upgrades, monitoring, and a compiled build that +would remove the need for dev dependencies on the droplet. diff --git a/docs/feasibility.md b/docs/feasibility.md index ce890f6..3030b1f 100644 --- a/docs/feasibility.md +++ b/docs/feasibility.md @@ -99,10 +99,15 @@ a suspended stream. The microphone is never reopened without a new tap. |---|---|---| | The public SDK has no speech-to-text API. | **unsupported** | No ASR in `sdk:` types, docs or skills. The official `asr` template says "The STT client itself is a blank stub... You pick your own provider". | -Decision: one server-side adapter for any service that implements the OpenAI -`POST /audio/transcriptions` contract (hosted or self-hosted Whisper). It is exercised only -against a test fake so far. **No real STT provider has been run**; none was available on the -development machine and choosing a paid one is Dan's decision (see "Decisions needed"). +Decision (updated after Dan asked for speech-to-text to be built in and to run on a droplet): +the bridge runs OpenAI's Whisper model itself, on the CPU, through ONNX Runtime +(`@huggingface/transformers` 4.3.2, model `onnx-community/whisper-base`, 8-bit weights). No +provider account, and recordings never leave the bridge host. An adapter for any external +OpenAI-compatible transcription endpoint remains as an alternative. + +Status: **tested with a real speech recording** (an 11 s archive clip, transcribed correctly in +about 1.6 s on the development desktop; see `docs/test-evidence.md`). **Not tested** with audio +from a G2 microphone, with background noise, with other languages or accents, or on a droplet. ### 4. Input events @@ -267,8 +272,7 @@ permissions and approval policy are unverified. 1. **Device access.** Nothing here is device-tested. The checklist is `docs/device-test-plan.md`. Lock-screen capture comes first because it can invalidate the product's first outcome. -2. **STT provider.** Hosted (per-minute cost, audio leaves your network) or self-hosted Whisper - (free, needs a machine). The adapter is the same either way. +2. ~~STT provider.~~ Decided 2026-11-18: built into the bridge. 3. **Target Hermes.** Which deployment and profile the bridge should point at, and a safe read-only test profile for the first real run. 4. **Distribution model**, given the per-build network whitelist: one build per deployment, or a diff --git a/docs/handoff/2026-11-18-slice-1.md b/docs/handoff/2026-11-18-slice-1.md index e4399cf..af6f9f1 100644 --- a/docs/handoff/2026-11-18-slice-1.md +++ b/docs/handoff/2026-11-18-slice-1.md @@ -13,13 +13,25 @@ should be read as Cody's assessment. The author's own checks are listed as such. | Repository | `git@git.xylo.gg:Xylo-Digital/hermeven.git` | | Base | None. The remote had no refs when work began (empty repository), so there is no base SHA. | | Branch | `feat/vertical-slice-1`, local only | -| Head under review | `4687cc01147e2167997aa6a252343933070fbebd` | -| Pushed | No. Nothing has been pushed; there is no PR. Pushing and merging are Dan's. | -| Follow-up commit | The commit that adds this file and `docs/test-evidence.md` changes documentation only. | +| First slice | `4687cc01147e2167997aa6a252343933070fbebd` | +| Head under review | The tip of the remote branch `cody/slice-1-review`: the first slice plus built-in speech-to-text and droplet deployment files (see "Added after the first slice"). | +| Pushed | To `cody/slice-1-review` only, at Dan's request on 2026-11-18. Dan works solo and has said no PR is needed. Nothing has been pushed to `main`. | Repository instructions: there were none to follow (no `AGENTS.md`, `CLAUDE.md`, `README` or `CONTRIBUTING` existed). The kickoff specification was the only instruction source. +## Added after the first slice + +Dan decided speech-to-text should be built into the software and that the bridge will run on a +DigitalOcean droplet. + +| Area | Paths | +|---|---| +| Built-in Whisper adapter, now the default `STT_PROVIDER` | `services/bridge/src/stt/builtinWhisper.ts`, `config.ts`, `app.ts`, `main.ts` | +| Tests | `services/bridge/test/builtinWhisper.test.ts`, `tests/real-stt/*` (with a public-domain speech fixture) | +| Deployment examples, **not run on a droplet** | `deploy/*`, `docs/deploy-droplet.md` | +| New dependency | `@huggingface/transformers` 4.3.2 (brings ONNX Runtime and `sharp`) | + ## Changed files Everything is new. 79 files at the head above. @@ -42,7 +54,8 @@ Full detail, including failures along the way, is in `docs/test-evidence.md`. |---|---| | `npm ci` | clean install, 0 vulnerabilities reported | | `npm run typecheck` | exit 0 | -| `npm test` | 122 passed, 0 failed (7 files) | +| `npm test` | 130 passed, 0 failed (8 files) | +| `npm run test:real-stt` | 4 passed, 0 failed | | `npm run test:simulator` | 6 passed, 0 failed; 10 consecutive runs of the final revision | | `npm run test:real-hermes` | 9 passed, 0 failed | | `npm run client:build` | built; bundle searched for server secrets, none | @@ -55,7 +68,7 @@ Full detail, including failures along the way, is in `docs/test-evidence.md`. | Fakes only | 122 tests | | Even simulator 0.9.5 | 6 scenarios, screenshots in `docs/evidence/simulator/` | | Real Hermes v0.23.1, stub model | 9 scenarios | -| Real STT | none | +| Real STT | 4 scenarios: built-in Whisper on one clean archive recording | | Real model or tools | none | | Physical device | **none** | @@ -93,15 +106,19 @@ Offered as places to look, not as findings. - The Hermes adapter does not yet check `/v1/capabilities` for durable idempotency at startup. - The client holds captured audio in memory for a possible resend until the user discards it. - The real-Hermes test covers neither approvals nor the `unknown` status. +- The built-in speech model is fetched from the Hugging Face hub at first start with no pinned + revision or hash, and runs in the bridge's own process (a measured 0.4 s event-loop pause). +- The silence threshold in `builtinWhisper.ts` was chosen without any audio from the glasses. +- The systemd hardening options in `deploy/` have never been run with ONNX Runtime. ## Blockers and open decisions | # | Item | Owner | |---|---|---| | 1 | Run `docs/device-test-plan.md`, starting with A13 (locked phone, pocket). | Dan | -| 2 | Choose an STT provider or a self-hosted endpoint. | Dan | +| 2 | ~~Choose an STT provider.~~ Decided: built in. Remaining: measure it on the droplet. | Dan | | 3 | Name the target Hermes deployment and a safe test profile. | Dan | -| 4 | Decide whether to push this branch and open a PR. | Dan | +| 4 | ~~Push and PR.~~ Decided: no PR; pushed to `cody/slice-1-review`. When to put it on `main` is still open. | Dan | | 5 | Independent architecture and security review of the head above. | Cody | | 6 | Distribution model given Even's per-build network whitelist. | Dan, later | diff --git a/docs/security.md b/docs/security.md index 9b8641e..9ae6057 100644 --- a/docs/security.md +++ b/docs/security.md @@ -50,8 +50,15 @@ Stated so they are not mistaken for protections. with developer access to the app's storage, can use it until it is revoked. 2. **Renewal needs only the current token.** A thief who renews before the owner notices keeps access until revoked or until the 90-day pairing lifetime ends. -3. **Audio leaves the device and, with a hosted STT provider, leaves your network.** A - self-hosted Whisper endpoint avoids this. The provider's own retention is outside our control. +3. **Audio leaves the phone for the bridge host.** With the default built-in speech model it + goes no further. With `STT_PROVIDER=openai-compatible` it is sent to that provider, whose + retention is outside our control. +3a. **The built-in model's files are downloaded from the Hugging Face hub on first start** and + are not pinned to a revision or checked against a known hash. A compromised hub account or + path could serve different weights. Pinning a revision is a follow-up. +3b. **While a recording is being transcribed the bridge can pause for a few hundred + milliseconds** (measured about 0.4 s), because the model runs in the same process. Harmless + for one user; a worker thread would remove it. 4. **In the simulator, raw audio frames are echoed to the WebView console.** Whether the phone does the same is unknown and is on the device checklist. If it does, recordings would be visible to whoever can read that console. diff --git a/docs/setup.md b/docs/setup.md index 452b5dc..841cad7 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -1,7 +1,8 @@ # Setup -Requirements: Node.js 22.13 or later, a Hermes install with the API server enabled, and (for -voice) an OpenAI-compatible transcription endpoint. +Requirements: Node.js 22.13 or later and a Hermes install with the API server enabled. Speech +recognition is built into the bridge (Whisper on the CPU, about 0.8 GB of memory); the first +start downloads about 80 MB of model files into `data/models`. ```sh npm ci @@ -98,4 +99,5 @@ npm run typecheck npm test # unit + integration, fakes only npm run test:simulator # needs a desktop session; opens the simulator window npm run test:real-hermes # needs the hermes CLI; uses a throwaway HERMES_HOME and a stub model +npm run test:real-stt # runs the built-in Whisper model; first run downloads it ``` diff --git a/docs/test-evidence.md b/docs/test-evidence.md index de46d9c..4bc895a 100644 --- a/docs/test-evidence.md +++ b/docs/test-evidence.md @@ -1,6 +1,8 @@ # Test evidence -Recorded 2026-11-18 on the development machine (Linux x64, Node 22.23.2) at commit `4687cc0`. +Recorded 2026-11-18 on the development machine (Linux x64, Node 22.23.2). The first slice was +recorded at commit `4687cc0`; the built-in speech-to-text section was added afterwards and all +suites were re-run with it in place. These are the results of commands that were actually run. Nothing here is device evidence. ## What kind of evidence each suite is @@ -10,6 +12,7 @@ These are the results of commands that were actually run. Nothing here is device | `npm test` | Client and bridge code, HTTP between them, SQLite, Even's `pretext` measurement, the SDK's event parser | Glasses, STT, Hermes | Hermeven's own logic and failure handling | Anything about Even hardware, real STT or real Hermes | | `npm run test:simulator` | The client running in Even's simulator 0.9.5 through the real SDK bridge; the bridge | STT, Hermes; audio is ALSA's silent null device | The app boots, draws, takes gestures and uploads audio in Even's own simulator | Hardware behaviour, real audio pacing, lock screen, lifecycle | | `npm run test:real-hermes` | The bridge and a real `hermes gateway` v0.23.1 | The language model behind Hermes | Hermes's admission, idempotency, session continuity and stop behave as the adapter assumes | A real model, tools, approvals, or Dan's deployment | +| `npm run test:real-stt` | The bridge and its built-in Whisper model, on a real speech recording | Glasses, Hermes | Speech uploaded as a capture is really transcribed and the words reach the agent | The G2 microphone, noise, accents, other languages, a droplet's speed | ## Results @@ -25,8 +28,8 @@ Exit 0, no diagnostics, for contracts, bridge, client and tests. ``` $ npm test - Test Files 7 passed (7) - Tests 122 passed (122) + Test Files 8 passed (8) + Tests 130 passed (130) ``` Run after a clean `npm ci`. Six consecutive full runs were green after the fix described under @@ -36,6 +39,7 @@ Run after a clean `npm ci`. Six consecutive full runs were green after the fix d |---|---|---| | `packages/contracts/test/contracts.test.ts` | 4 | Schema acceptance and rejection, error-code retryability | | `services/bridge/test/units.test.ts` | 13 | Config guards, credential expiry and renewal, pairing codes, adapter helpers | +| `services/bridge/test/builtinWhisper.test.ts` | 8 | Built-in STT adapter with a stand-in recogniser: silence gate, language, ordering, cancel, load failure | | `apps/even-client/test/reducer.test.ts` | 24 | State transitions, cancellation, stale and late results, connection loss | | `apps/even-client/test/layout.test.ts` | 16 | Pagination, Unicode, long answers, plain-text conversion, HUD frames fit | | `apps/even-client/test/events.test.ts` | 8 | Gesture mapping through the SDK's parser, the tap-has-no-eventType quirk | @@ -142,6 +146,50 @@ Two of the nine failed on the first run because the stub model mistook Hermes's Timings seen here (stub model, loopback, one sample each): first turn about 1.4 s in Hermes; later turns well under 1 s. These are not performance figures for anything real. +### Built-in speech-to-text, real model, real speech + +``` +$ npm run test:real-stt + Tests 4 passed (4) +``` + +`onnx-community/whisper-base`, 8-bit weights, run in the bridge process on the CPU. The input is +`tests/real-stt/fixtures/jfk.wav`, 11.0 s of clean archive speech, uploaded through +`POST /v1/turns` as raw PCM exactly as the client uploads a capture. + +| Scenario | Result | +|---|---| +| Real speech is transcribed and the transcript is what the (fake) agent receives | pass | +| Three seconds of digital silence: `stt_empty`, the agent is not called | pass | +| Three seconds of very quiet noise: `stt_empty` | pass | +| A second recording with the model already loaded | pass | + +Transcript produced: "And so my fellow Americans, ask not what your country can do for you, ask +what you can do for your country." That matches the recording. + +Measurements from this run, one sample each, on an Intel i7-13850HX desktop: + +| Measurement | Value | +|---|---| +| Model load (files already cached) | 1.2 to 3.8 s | +| 11.0 s of speech | 1.6 s | +| Memory (resident) after loading / after transcribing | about 0.5 GB / 0.8 GB | +| Longest event-loop pause during transcription | 0.39 s | +| Same clip with the process pinned to one core | 1.7 s (no slower) | + +Things this run also showed that are worth knowing: + +- When the same clip was cut off mid-sentence at 6 s, the model wrote "ask not what you are + coming" for the truncated ending. A recording that stops mid-word (for example at the capture + cap) can end in invented words. +- Whisper produces short invented phrases for silent input, which is why silence is detected by + level before the model runs. The level threshold (-55 dBFS) was chosen without any G2 audio and + may be wrong for the real microphone in either direction. +- Nothing here measures a droplet. See `docs/deploy-droplet.md`. + +The bridge process was also started with default settings: it logged `stt.loading`, then +`stt.ready`, and answered `/healthz` throughout. + ### Build and packaging ``` @@ -175,7 +223,9 @@ unauthenticated `/v1/device` answered 401, `bridge:cli -- pair` printed a code, - A physical G2, the R1 ring, the Even phone app, any phone. - The microphone with the phone locked or the app in the background. -- Real speech-to-text, in any language. +- Speech-to-text on audio from the glasses, with background noise, or in any language but English. +- The external (`openai-compatible`) STT adapter against a real provider. +- Anything on a DigitalOcean droplet: `docs/deploy-droplet.md` and `deploy/*` are untested. - A real language model, real tools, a real approval prompt. - Hermes `waiting_for_approval`, `unknown`, `interrupted` and stopped-short runs against real Hermes (fake only). diff --git a/package-lock.json b/package-lock.json index 0cc20f3..c8e57db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -797,6 +797,544 @@ "resolved": "apps/even-client", "link": true }, + "node_modules/@huggingface/jinja": { + "version": "0.5.13", + "resolved": "https://registry.npmjs.org/@huggingface/jinja/-/jinja-0.5.13.tgz", + "integrity": "sha512-jM17MqFily1iyT/1LD3r5w8/CZiyapVB0+7vOw48PfVtzyKsXStmHE4jVTyDAD05Tqv3un1xrS9ILUU1ugQAYQ==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@huggingface/tokenizers": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@huggingface/tokenizers/-/tokenizers-0.2.0.tgz", + "integrity": "sha512-LidMHe1FpcSYH4vcSjXooda34pC0M8m1gmDOv7SQi6Iv+ib1zX7J3sHBCC9/3FPCkn2k1b55FneVqMRxrr99pg==", + "license": "Apache-2.0" + }, + "node_modules/@huggingface/transformers": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/@huggingface/transformers/-/transformers-4.3.2.tgz", + "integrity": "sha512-V3+dqf3iWlRYJ9I9GreM3zGQd0lAXnnoPeddmkOQYWAEE4l/+Fi6p7tx/qVUJlKQgLXGim2W76rTOzz+eC0i7g==", + "license": "Apache-2.0", + "dependencies": { + "@huggingface/jinja": "^0.5.10", + "@huggingface/tokenizers": "^0.2.0", + "onnxruntime-node": "1.30.0", + "onnxruntime-web": "1.31.0-dev.20260914-8d85527a0", + "sharp": "^0.35.4" + } + }, + "node_modules/@img/colour": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", + "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.35.5.tgz", + "integrity": "sha512-QRUlFQ0WxvdWyqqG/WtI3iupfD5rBzmCHXSdPsY91sAtVtTo7Q4cb6zOccZ3gqEqkr0f1As1ehLqmEpDsRf+lg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.35.5.tgz", + "integrity": "sha512-+BR255RhDlpygUpOc/Jdt1nT6DQ3XG/ERo5wbcdOf5Q320dKtPCKPLR1LJs9VGXRaMa8l1uUa0tkCNOXiAxZUw==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-freebsd-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.5.tgz", + "integrity": "sha512-Y/z91nEZ4uIBX5X3nfTovjU9lHNKFYbL2lpHCLVNmXQK03VIZvXBBt0KxbPGp2SdGSF+2mQU4e+hQaWOt86iAw==", + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.3.4.tgz", + "integrity": "sha512-5R89nBYiRdUlSWJxPhO+GVtaXzXSxKnRu/xqMn3KTA3L9EB9Oy/P+Nn2f2vlhPuUdy/Zusb2DarbyTpGCfEDuw==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.3.4.tgz", + "integrity": "sha512-iR2OKH80yi0U+dUplyh3/xdpFvps6YkCwsXenIJxqxR1v9o+xtKTGbS9H7cps+2Vxjc8B1j96p75NmTGjIhtpQ==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.3.4.tgz", + "integrity": "sha512-LmRtTsOHuvM2+wlO2Db37dx5MiZhB0FvSunciw48YjdOkZz9KAiRbm8ujeMOA1INqmei5NapFxYEK1D1ZSidmw==", + "cpu": [ + "arm" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.3.4.tgz", + "integrity": "sha512-Y3dgX/6lE2QhQb+Gxy0WZxfg9MEm/JBjamZpS2IklP7xIQoKN4hzAm7KcMVGtaVDt3neE9OKBC7vAfonA/Lr1A==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-ppc64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.3.4.tgz", + "integrity": "sha512-Le6boB8Tai0Nis+gIxIpKx68UDVVIqdR8Tin5Yf1z2LJJQLDJvCDRqRu+jC2qCoD+eIomonmOwB4smBRxfVpYQ==", + "cpu": [ + "ppc64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-riscv64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.3.4.tgz", + "integrity": "sha512-aHkkIEHPRdQEegJN20MLmGtxYD9R2wQr3Cwpddnu5+YKMt6Uzax7S9h5gpZTo8wyrGuZSlfQ63OevL5mTyOC7Q==", + "cpu": [ + "riscv64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.3.4.tgz", + "integrity": "sha512-ra/mB6MikESDUO7Yg+Mi95bFBb9GsObURuhnOv3OqknjGe9sZrG8tCe9q0xSIGrtLgvgw0gKnFWcK4blSgQOuQ==", + "cpu": [ + "s390x" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.3.4.tgz", + "integrity": "sha512-GJ//SSXbnwSDes02umB3nDJLFcQzw8a18V8fyhqr6tV515tOEMdImjjxj1AoafMRz56F3PHgftnj1QEKSU1zkw==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.3.4.tgz", + "integrity": "sha512-hvulFwtjUcagsis6BBxHwGFwWoNZjgYmULGVrZcyfNbjA8hKILbRxGg15/7w5HDyXHXUos/j6baAWqnCyQ2DWA==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.4.tgz", + "integrity": "sha512-6zXKeE/p39I1AmA3cJG35eyBGNqNddLnUXjhwBnsGjFPWqf5VKkDBEqaEkPDoTEtkxwi2vv8Tcr2mDyP4So7Fg==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.35.5.tgz", + "integrity": "sha512-LEaXK2WdXVK5ykcw0buWyPMsmLLL2vpHLD6yrNSW+JGEL3BZPA4tpKN6iaMc4AxTTAoaX/sU1rOL51lcIz48ZQ==", + "cpu": [ + "arm" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.35.5.tgz", + "integrity": "sha512-LYVx5JTsOM2CBzmxreh+nl64/3H6Xb09iSLknqH47z2T2DFFxDeFLP5y4dJwe6H7uGQlHPyEEtIqyo3DYsRwdQ==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-ppc64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.35.5.tgz", + "integrity": "sha512-QVxAAq8evVRI9ia2vqgwrmWucn5Dfv+JdWzj75pD8omHLPSP7f8p20O8jxzjCcuCEQEOtYOZUmX1hkiZ0kdevA==", + "cpu": [ + "ppc64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-ppc64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-riscv64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.35.5.tgz", + "integrity": "sha512-LtdreXguaavKODPIfzJ4kffx7UNt1omwtK0rch4EBbbSTXPnxWmYSayXdLJw0fJzQ97kHt1gL/yh4tvU+nCyRQ==", + "cpu": [ + "riscv64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-riscv64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.35.5.tgz", + "integrity": "sha512-UZasTOFiYzotTsGOCu42BfUzP6Tu6Do/947iRm1RsLKvlllxwGcn4RN27LibGWceix4Y+Pmw3jsnTcCQIgWjqA==", + "cpu": [ + "s390x" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.35.5.tgz", + "integrity": "sha512-SxFtLTeJInhAA9Q836kux2vZNeOBQEx658qvbboZScr0wIARym3IcGmW7KpVD5sbVg0Ojy+udFQdayYIZyoNog==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.35.5.tgz", + "integrity": "sha512-9HbMclmI1zlNkFRs3z9/eBtDjfD0sGlrX1z6b1qwmiFY5ElDLh4BC0LPBdVp7z1DXFiKlIcznf+ZlsuZzLxQqg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.5.tgz", + "integrity": "sha512-4KOphqB035HrVdqLZfCgMzzERrQkkzOwRhl4OAkRO1YCldbaFjySXMaK534Mo0V+LndnlJk+sbUyLeU0ULyD1A==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz", + "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==", + "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.11.3" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-wasm32/node_modules/@emnapi/runtime": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", + "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@img/sharp-webcontainers-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.5.tgz", + "integrity": "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA==", + "cpu": [ + "wasm32" + ], + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.35.5.tgz", + "integrity": "sha512-X4t7g+7ZA5DKblCBEXGjUqqemj4vczING/5viFwAL8h4N3qYeyjwdCvRLHi4EdOUI+2Z7UFlp1VM+p/AuEtm6Q==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.35.5.tgz", + "integrity": "sha512-5Zm82LoBc43nhwNybZlG7Y1KO//Zhsn306fQl29ZOuStHLGTo3BWL83q3cznX0poxSAMuYL1On/BHBxkBeKr6A==", + "cpu": [ + "ia32" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.35.5.tgz", + "integrity": "sha512-x76eH0vEiHlcMQu8Y8IenntaACtddpT6W0wmXtWrnKcnKI7ME5DdgqhAD6SEWOEl1v2zDvkZDhFA9KnURwpfqg==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", @@ -864,6 +1402,63 @@ "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", "license": "MIT" }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.5.tgz", + "integrity": "sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.1.tgz", + "integrity": "sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.1.tgz", + "integrity": "sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==", + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.2.tgz", + "integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==", + "license": "BSD-3-Clause" + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.19", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", @@ -1218,7 +1813,6 @@ "version": "22.20.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz", "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.21.0" @@ -1268,6 +1862,15 @@ "integrity": "sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA==", "license": "MIT" }, + "node_modules/adm-zip": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.6.1.tgz", + "integrity": "sha512-Xwrja8nx9e5o2N1my4DsKCeKpdrnACyr1wtbPxBDgGzKzKyE9kRtBFA8mWldI+RVlD7CBZNWY/wQ2+ydwOR6kQ==", + "license": "MIT", + "engines": { + "node": ">=14.0" + } + }, "node_modules/ajv": { "version": "8.20.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", @@ -1391,6 +1994,40 @@ "url": "https://opencollective.com/express" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/define-properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "license": "MIT", + "dependencies": { + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -1404,12 +2041,29 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=8" } }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", @@ -1458,6 +2112,18 @@ "@esbuild/win32-x64": "0.28.2" } }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/estree-walker": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", @@ -1629,6 +2295,12 @@ "node": ">=20" } }, + "node_modules/flatbuffers": { + "version": "25.9.23", + "resolved": "https://registry.npmjs.org/flatbuffers/-/flatbuffers-25.9.23.tgz", + "integrity": "sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==", + "license": "Apache-2.0" + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1643,6 +2315,67 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/global-agent": { + "version": "4.1.7", + "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-4.1.7.tgz", + "integrity": "sha512-pxaZqdsMwPA4i7TuRKpDUONm2xGRjvYdRoidCQz7VleUKVuUfh/4p5Q3QDTGrpAE5Kz5TxxcZ+uqEgTkoKRNtg==", + "license": "BSD-3-Clause", + "dependencies": { + "globalthis": "^1.0.2", + "matcher": "^4.0.0", + "semver": "^7.3.5", + "serialize-error": "^8.1.0" + }, + "engines": { + "node": ">=10.0" + } + }, + "node_modules/globalthis": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz", + "integrity": "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==", + "license": "MIT", + "dependencies": { + "define-properties": "^1.2.1", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/guid-typescript": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz", + "integrity": "sha512-Y8T4vYhEfwJOTbouREvG+3XDsjr8E3kIr7uf+JZ0BYloFsttiHU0WfvANVsR7TxNUJa/WpCnw/Ino/p+DeBhBQ==", + "license": "ISC" + }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ipaddr.js": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.5.0.tgz", @@ -1971,6 +2704,12 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, "node_modules/magic-string": { "version": "1.4.5", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", @@ -1981,6 +2720,21 @@ "@jridgewell/sourcemap-codec": "^1.6.0" } }, + "node_modules/matcher": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/matcher/-/matcher-4.0.0.tgz", + "integrity": "sha512-S6x5wmcDmsDRRU/c2dkccDwQPXoFczc5+HpQ2lON8pnvHlnvHAHj5WlLVvw6n6vNyHuVugYrFohYxbS+pvFpKQ==", + "license": "MIT", + "dependencies": { + "escape-string-regexp": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/nanoid": { "version": "3.3.20", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", @@ -2009,6 +2763,15 @@ "node": "^18 || ^20 || >= 21" } }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/obug": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", @@ -2032,6 +2795,49 @@ "node": ">=14.0.0" } }, + "node_modules/onnxruntime-common": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.30.0.tgz", + "integrity": "sha512-7fdVWjAID1dVhH/G8qK3APARunV4VkBFoCQAP7qp4Wkab0mrorvmc+sqiT+mKXOzDqdjN5j+/Z9nb4gzNPWcyA==", + "license": "MIT" + }, + "node_modules/onnxruntime-node": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.30.0.tgz", + "integrity": "sha512-twhs1C2C/BFkz1yc5OY0KIU2GUq6DURO7hD4bx5Q2Qy3nAMJwRXW8xU3NVczE29VA9lolLOYepoD8fjTGOfIqw==", + "hasInstallScript": true, + "license": "MIT", + "os": [ + "win32", + "darwin", + "linux" + ], + "dependencies": { + "adm-zip": "^0.6.0", + "global-agent": "^4.1.3", + "onnxruntime-common": "1.30.0" + } + }, + "node_modules/onnxruntime-web": { + "version": "1.31.0-dev.20260914-8d85527a0", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.31.0-dev.20260914-8d85527a0.tgz", + "integrity": "sha512-Iy7rtadoBgxS/LLvDr3QW38DB1PNXRnr0GJMcL0TAt7c9qjgVQl83UlGCVyeAnK2InpmW8Uc3PL8XIuqtDeF6g==", + "license": "MIT", + "dependencies": { + "flatbuffers": "^25.1.24", + "guid-typescript": "^1.0.9", + "long": "^5.2.3", + "onnxruntime-common": "1.31.0-dev.20260911-2a43ec07e", + "platform": "^1.3.6", + "protobufjs": "^7.2.4" + } + }, + "node_modules/onnxruntime-web/node_modules/onnxruntime-common": { + "version": "1.31.0-dev.20260911-2a43ec07e", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.31.0-dev.20260911-2a43ec07e.tgz", + "integrity": "sha512-gBuF6U32YErKIAt+yD7DeGBpjRxhJ1uJwako6ygjokSZULDU6Pd+KWComX8Tumk1hYVHRxjPj7mdMnD0ryAPOw==", + "license": "MIT" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -2089,6 +2895,12 @@ "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", "license": "MIT" }, + "node_modules/platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", + "license": "MIT" + }, "node_modules/postcss": { "version": "8.5.33", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", @@ -2134,6 +2946,29 @@ ], "license": "MIT" }, + "node_modules/protobufjs": { + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.6.tgz", + "integrity": "sha512-dYDWdjSl5RNb7SgPxGQcRU+GtvP7s2fpkrY0r432PcOIaZ0/rBcxEZnQN67iJhFuQiVw754JDoPruPCNdGsbjg==", + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.5", + "@protobufjs/eventemitter": "^1.1.1", + "@protobufjs/fetch": "^1.1.1", + "@protobufjs/float": "^1.0.2", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.1", + "@types/node": ">=13.7.0", + "long": "^5.3.2" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/quick-format-unescaped": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", @@ -2274,12 +3109,76 @@ "node": ">=10" } }, + "node_modules/serialize-error": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-8.1.0.tgz", + "integrity": "sha512-3NnuWfM6vBYoy5gZFvHiYsVbafvI9vZv/+jlIigFn4oP4zjNPK3LhcY0xSCgeb1a5L8jO71Mit9LlNoi2UfDDQ==", + "license": "MIT", + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/set-cookie-parser": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-3.2.3.tgz", "integrity": "sha512-bDO7NdAkLprNt3BNl3LAh0oVnOS5+WspzxOxiboo7vRIyTqj2pvFmNWYEFynSGQgpJ+7yG/9nc/aSG20UDBUpg==", "license": "MIT" }, + "node_modules/sharp": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.5.tgz", + "integrity": "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g==", + "license": "Apache-2.0", + "dependencies": { + "@img/colour": "^1.1.0", + "detect-libc": "^2.1.2", + "semver": "^7.8.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.35.5", + "@img/sharp-darwin-x64": "0.35.5", + "@img/sharp-freebsd-wasm32": "0.35.5", + "@img/sharp-libvips-darwin-arm64": "1.3.4", + "@img/sharp-libvips-darwin-x64": "1.3.4", + "@img/sharp-libvips-linux-arm": "1.3.4", + "@img/sharp-libvips-linux-arm64": "1.3.4", + "@img/sharp-libvips-linux-ppc64": "1.3.4", + "@img/sharp-libvips-linux-riscv64": "1.3.4", + "@img/sharp-libvips-linux-s390x": "1.3.4", + "@img/sharp-libvips-linux-x64": "1.3.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4", + "@img/sharp-libvips-linuxmusl-x64": "1.3.4", + "@img/sharp-linux-arm": "0.35.5", + "@img/sharp-linux-arm64": "0.35.5", + "@img/sharp-linux-ppc64": "0.35.5", + "@img/sharp-linux-riscv64": "0.35.5", + "@img/sharp-linux-s390x": "0.35.5", + "@img/sharp-linux-x64": "0.35.5", + "@img/sharp-linuxmusl-arm64": "0.35.5", + "@img/sharp-linuxmusl-x64": "0.35.5", + "@img/sharp-webcontainers-wasm32": "0.35.5", + "@img/sharp-win32-arm64": "0.35.5", + "@img/sharp-win32-ia32": "0.35.5", + "@img/sharp-win32-x64": "0.35.5" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, "node_modules/sonic-boom": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", @@ -2377,10 +3276,8 @@ "version": "2.9.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz", "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==", - "dev": true, "license": "0BSD", - "optional": true, - "peer": true + "optional": true }, "node_modules/tsx": { "version": "4.23.15", @@ -2400,6 +3297,18 @@ "fsevents": "~2.3.3" } }, + "node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", @@ -2418,7 +3327,6 @@ "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", - "dev": true, "license": "MIT" }, "node_modules/vite": { @@ -2608,6 +3516,7 @@ "dependencies": { "@fastify/cors": "^11.4.3", "@hermeven/contracts": "*", + "@huggingface/transformers": "^4.3.2", "@sinclair/typebox": "^0.34.52", "better-sqlite3": "^13.2.0", "fastify": "^5.12.8", diff --git a/package.json b/package.json index ed582a7..01d1624 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "bridge:cli": "npm run -w @hermeven/bridge cli --", "client:dev": "npm run -w @hermeven/even-client dev --", "client:build": "npm run -w @hermeven/even-client build", - "simulate": "node node_modules/@evenrealities/evenhub-simulator/bin/index.js" + "simulate": "node node_modules/@evenrealities/evenhub-simulator/bin/index.js", + "test:real-stt": "vitest run --config tests/real-stt/vitest.config.ts" }, "devDependencies": { "@types/node": "^22.19.0", diff --git a/services/bridge/package.json b/services/bridge/package.json index 5732a5b..3c62874 100644 --- a/services/bridge/package.json +++ b/services/bridge/package.json @@ -10,6 +10,7 @@ "dependencies": { "@fastify/cors": "^11.4.3", "@hermeven/contracts": "*", + "@huggingface/transformers": "^4.3.2", "@sinclair/typebox": "^0.34.52", "better-sqlite3": "^13.2.0", "fastify": "^5.12.8", diff --git a/services/bridge/src/app.ts b/services/bridge/src/app.ts index 607e3ce..f66e5d7 100644 --- a/services/bridge/src/app.ts +++ b/services/bridge/src/app.ts @@ -7,11 +7,13 @@ import type { HermesAdapter } from './hermes/adapter.ts'; import { HermesRunsAdapter } from './hermes/runsAdapter.ts'; import { buildServer } from './server.ts'; import { NoSttAdapter, type SttAdapter } from './stt/adapter.ts'; +import { BuiltinWhisperStt } from './stt/builtinWhisper.ts'; import { OpenAiCompatibleStt } from './stt/openaiCompatible.ts'; import { TurnEngine, type EngineLog, type EngineTiming } from './turns.ts'; export interface Bridge { app: FastifyInstance; + stt: SttAdapter; db: Db; devices: Devices; engine: TurnEngine; @@ -35,6 +37,9 @@ export function sttFromConfig(config: BridgeConfig): SttAdapter { if (config.stt.provider === 'openai-compatible') { return new OpenAiCompatibleStt({ baseUrl: config.stt.baseUrl, apiKey: config.stt.apiKey, model: config.stt.model }); } + if (config.stt.provider === 'builtin') { + return new BuiltinWhisperStt({ model: config.stt.model, dtype: config.stt.dtype, cacheDir: config.stt.cacheDir }); + } return new NoSttAdapter(); } @@ -70,6 +75,7 @@ export async function createBridge( return { app, + stt, db, devices, engine, diff --git a/services/bridge/src/config.ts b/services/bridge/src/config.ts index e00845c..5d95c42 100644 --- a/services/bridge/src/config.ts +++ b/services/bridge/src/config.ts @@ -22,10 +22,14 @@ export interface BridgeConfig { requestTimeoutMs: number; }; stt: { - provider: 'none' | 'openai-compatible'; + provider: 'none' | 'builtin' | 'openai-compatible'; baseUrl: string; apiKey: string; + /** Hub model id for `builtin`; provider model name for `openai-compatible`. */ model: string; + /** `builtin` only: weight precision and where model files are cached. */ + dtype: string; + cacheDir: string; }; limits: { captureMaxSeconds: number; @@ -122,9 +126,19 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig { if (parsed.origin !== origin) throw new ConfigError(`HERMEVEN_ALLOWED_ORIGINS entry must be scheme://host[:port]: ${origin}`); } - const sttProvider = (env.STT_PROVIDER || 'none') as BridgeConfig['stt']['provider']; - if (sttProvider !== 'none' && sttProvider !== 'openai-compatible') { - throw new ConfigError('STT_PROVIDER must be "none" or "openai-compatible"'); + // Built-in Whisper is the default: voice works with no provider account and no audio + // leaving the bridge host. + const sttProvider = (env.STT_PROVIDER || 'builtin') as BridgeConfig['stt']['provider']; + if (sttProvider !== 'none' && sttProvider !== 'builtin' && sttProvider !== 'openai-compatible') { + throw new ConfigError('STT_PROVIDER must be "builtin", "openai-compatible" or "none"'); + } + const sttModel = env.STT_MODEL || (sttProvider === 'builtin' ? 'onnx-community/whisper-base' : ''); + if (sttProvider === 'builtin' && !/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(sttModel)) { + throw new ConfigError('STT_MODEL must be a Hugging Face model id such as onnx-community/whisper-base'); + } + const sttDtype = env.STT_DTYPE || 'q8'; + if (!['q8', 'q4', 'fp32', 'fp16', 'int8', 'uint8'].includes(sttDtype)) { + throw new ConfigError('STT_DTYPE must be one of q8, q4, fp32, fp16, int8, uint8'); } let sttBaseUrl = ''; if (sttProvider === 'openai-compatible') { @@ -154,7 +168,9 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig { provider: sttProvider, baseUrl: sttBaseUrl, apiKey: env.STT_API_KEY || '', - model: env.STT_MODEL || '', + model: sttModel, + dtype: sttDtype, + cacheDir: env.STT_CACHE_DIR || './data/models', }, limits: { captureMaxSeconds, diff --git a/services/bridge/src/main.ts b/services/bridge/src/main.ts index 7dfc6d7..3f9dc55 100644 --- a/services/bridge/src/main.ts +++ b/services/bridge/src/main.ts @@ -1,6 +1,7 @@ import { LOG_REDACT, createBridge } from './app.ts'; import { ConfigError, loadConfig } from './config.ts'; import { loadEnvFile } from './env.ts'; +import { BuiltinWhisperStt } from './stt/builtinWhisper.ts'; async function main(): Promise { loadEnvFile(); @@ -10,6 +11,17 @@ async function main(): Promise { }); await bridge.app.listen({ host: config.host, port: config.port }); + // Load the built-in speech model in the background so the first spoken question is not + // slowed by it. On a first start this downloads the model files. + if (bridge.stt instanceof BuiltinWhisperStt) { + const started = Date.now(); + bridge.app.log.info({ model: config.stt.model, dtype: config.stt.dtype }, 'stt.loading'); + bridge.stt.warm().then( + () => bridge.app.log.info({ load_ms: Date.now() - started }, 'stt.ready'), + () => bridge.app.log.error({ model: config.stt.model }, 'stt.load_failed'), + ); + } + let closing = false; const stop = (signal: string) => { if (closing) return; diff --git a/services/bridge/src/stt/builtinWhisper.ts b/services/bridge/src/stt/builtinWhisper.ts new file mode 100644 index 0000000..a8bd7d1 --- /dev/null +++ b/services/bridge/src/stt/builtinWhisper.ts @@ -0,0 +1,122 @@ +import { AUDIO_FORMAT } from '@hermeven/contracts'; +import { SttError, type SttAdapter, type TranscribeRequest } from './adapter.ts'; + +/** + * Built-in speech-to-text: OpenAI's Whisper model run inside the bridge process + * on the CPU (ONNX Runtime via @huggingface/transformers). No audio leaves the + * bridge host and no provider account is needed. + * + * The model files are downloaded from the Hugging Face hub the first time the + * bridge starts and are then read from `cacheDir`. + */ +export interface BuiltinWhisperOptions { + /** Hub id, for example `onnx-community/whisper-base` (multilingual) or `...-base.en`. */ + model: string; + /** Weight precision. `q8` is the small, CPU-friendly default. */ + dtype: string; + cacheDir: string; + /** Test seam: replaces the model loader. */ + load?: () => Promise; +} + +export type Recognizer = (audio: Float32Array, options: Record) => Promise<{ text?: unknown } | Array<{ text?: unknown }>>; + +/** + * Below this RMS level the capture is treated as silence and not transcribed. + * Whisper invents short phrases ("Thank you.") for silent input, which would + * otherwise be sent to the agent as if the user had said them. -55 dBFS. + */ +export const SILENCE_RMS = 0.0018; + +export function pcmToFloat32(pcm: Buffer): Float32Array { + const samples = new Float32Array(Math.floor(pcm.length / 2)); + for (let i = 0; i < samples.length; i++) samples[i] = pcm.readInt16LE(i * 2) / 32768; + return samples; +} + +export function rms(samples: Float32Array): number { + if (samples.length === 0) return 0; + let sum = 0; + for (let i = 0; i < samples.length; i++) sum += samples[i]! * samples[i]!; + return Math.sqrt(sum / samples.length); +} + +/** Whisper marks non-speech with bracketed or parenthesised tags; those are not words. */ +export function cleanTranscript(text: string): string { + return text + .replace(/\[[^\]]*\]|\([^)]*\)/g, ' ') + .replace(/\s+/g, ' ') + .trim(); +} + +export class BuiltinWhisperStt implements SttAdapter { + readonly configured = true; + private recognizer: Promise | null = null; + /** One transcription at a time: the model is CPU-bound and this is a single-user bridge. */ + private queue: Promise = Promise.resolve(); + + constructor(private readonly opts: BuiltinWhisperOptions) {} + + /** Load the model now (downloading it on first use) so the first question is not slow. */ + async warm(): Promise { + await this.load(); + } + + private load(): Promise { + if (!this.recognizer) { + const loading = (this.opts.load ?? (() => this.loadModel()))(); + this.recognizer = loading; + // A failed load (no network on first start) must be retried on the next request. + loading.catch(() => { + if (this.recognizer === loading) this.recognizer = null; + }); + } + return this.recognizer; + } + + private async loadModel(): Promise { + const { pipeline } = await import('@huggingface/transformers'); + const asr = await pipeline('automatic-speech-recognition', this.opts.model, { + dtype: this.opts.dtype as never, + cache_dir: this.opts.cacheDir, + }); + return asr as unknown as Recognizer; + } + + async transcribe(request: TranscribeRequest): Promise { + const samples = pcmToFloat32(request.pcm); + if (samples.length < AUDIO_FORMAT.sampleRate / 10 || rms(samples) < SILENCE_RMS) return ''; + + const run = this.queue.then(async () => { + if (request.signal.aborted) throw new DOMException('Aborted', 'AbortError'); + let recognizer: Recognizer; + try { + recognizer = await this.load(); + } catch { + throw new SttError('unavailable', 'The speech model could not be loaded'); + } + // English-only models take no language argument; multilingual ones are told the + // language from the device locale rather than left to guess it from a short clip. + const options: Record = this.opts.model.endsWith('.en') + ? {} + : { language: request.locale.split('-')[0]!.toLowerCase(), task: 'transcribe' }; + try { + const out = await recognizer(samples, options); + const text = Array.isArray(out) ? out.map((o) => String(o.text ?? '')).join(' ') : String(out.text ?? ''); + return cleanTranscript(text); + } catch { + throw new SttError('failed', 'The speech model failed on this recording'); + } + }); + this.queue = run.catch(() => undefined); + + // Inference cannot be interrupted. On cancel or deadline the caller stops waiting; the + // result is discarded when it arrives and the queue keeps later requests in order. + return new Promise((resolve, reject) => { + const onAbort = () => reject(new DOMException('Aborted', 'AbortError')); + if (request.signal.aborted) return onAbort(); + request.signal.addEventListener('abort', onAbort, { once: true }); + run.then(resolve, reject).finally(() => request.signal.removeEventListener('abort', onAbort)); + }); + } +} diff --git a/services/bridge/test/builtinWhisper.test.ts b/services/bridge/test/builtinWhisper.test.ts new file mode 100644 index 0000000..df09329 --- /dev/null +++ b/services/bridge/test/builtinWhisper.test.ts @@ -0,0 +1,125 @@ +import { describe, expect, it } from 'vitest'; +import { SttError } from '../src/stt/adapter.ts'; +import { BuiltinWhisperStt, cleanTranscript, pcmToFloat32, rms, SILENCE_RMS, type Recognizer } from '../src/stt/builtinWhisper.ts'; + +/** These use a stand-in recogniser. The real model is exercised by `npm run test:real-stt`. */ +function tone(seconds: number, amplitude = 8000): Buffer { + const buf = Buffer.alloc(Math.floor(seconds * 16000) * 2); + for (let i = 0; i < buf.length / 2; i++) buf.writeInt16LE(Math.round(Math.sin(i / 5) * amplitude), i * 2); + return buf; +} +const never = new AbortController().signal; + +function make(recognizer: Recognizer, model = 'onnx-community/whisper-base') { + let loads = 0; + const calls: Array<{ samples: number; options: Record }> = []; + const stt = new BuiltinWhisperStt({ + model, + dtype: 'q8', + cacheDir: '/nonexistent', + load: async () => { + loads += 1; + return async (audio, options) => { + calls.push({ samples: audio.length, options }); + return recognizer(audio, options); + }; + }, + }); + return { stt, calls, loads: () => loads }; +} + +describe('built-in Whisper adapter', () => { + it('converts PCM to normalised floats', () => { + const buf = Buffer.alloc(6); + buf.writeInt16LE(32767, 0); + buf.writeInt16LE(-32768, 2); + buf.writeInt16LE(0, 4); + const f = pcmToFloat32(buf); + expect(f[0]).toBeCloseTo(1, 3); + expect(f[1]).toBe(-1); + expect(f[2]).toBe(0); + expect(rms(pcmToFloat32(tone(1)))).toBeGreaterThan(SILENCE_RMS * 50); + }); + + it('never loads or runs the model for silence or for a clip too short to hold a word', async () => { + const { stt, calls, loads } = make(async () => ({ text: 'Thank you.' })); + expect(await stt.transcribe({ pcm: Buffer.alloc(32000), locale: 'en-US', signal: never })).toBe(''); + expect(await stt.transcribe({ pcm: tone(1, 20), locale: 'en-US', signal: never })).toBe(''); + expect(await stt.transcribe({ pcm: tone(0.05), locale: 'en-US', signal: never })).toBe(''); + expect(calls).toHaveLength(0); + expect(loads()).toBe(0); + }); + + it('passes the device language to a multilingual model and nothing to an English-only one', async () => { + const multi = make(async () => ({ text: ' Bonjour. ' })); + expect(await multi.stt.transcribe({ pcm: tone(1), locale: 'fr-CA', signal: never })).toBe('Bonjour.'); + expect(multi.calls[0]).toEqual({ samples: 16000, options: { language: 'fr', task: 'transcribe' } }); + const en = make(async () => ({ text: 'Hello.' }), 'onnx-community/whisper-base.en'); + await en.stt.transcribe({ pcm: tone(1), locale: 'fr-CA', signal: never }); + expect(en.calls[0]!.options).toEqual({}); + }); + + it('strips non-speech tags, so a clip of only noise tags is empty', () => { + expect(cleanTranscript(' [BLANK_AUDIO] ')).toBe(''); + expect(cleanTranscript('(wind blowing) Hello there [MUSIC]')).toBe('Hello there'); + }); + + it('runs one transcription at a time, in order', async () => { + let running = 0; + let peak = 0; + const { stt } = make(async (audio) => { + running += 1; + peak = Math.max(peak, running); + await new Promise((r) => setTimeout(r, 30)); + running -= 1; + return { text: `len ${audio.length}` }; + }); + const results = await Promise.all([1, 2, 3].map((s) => stt.transcribe({ pcm: tone(s), locale: 'en-US', signal: never }))); + expect(results).toEqual(['len 16000', 'len 32000', 'len 48000']); + expect(peak).toBe(1); + }); + + it('a cancelled request stops waiting at once and does not block the next one', async () => { + const { stt } = make(async () => { + await new Promise((r) => setTimeout(r, 150)); + return { text: 'slow' }; + }); + const abort = new AbortController(); + const first = stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: abort.signal }); + setTimeout(() => abort.abort(), 20); + const started = Date.now(); + await expect(first).rejects.toMatchObject({ name: 'AbortError' }); + expect(Date.now() - started).toBeLessThan(120); + expect(await stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: never })).toBe('slow'); + const already = new AbortController(); + already.abort(); + await expect(stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: already.signal })).rejects.toMatchObject({ name: 'AbortError' }); + }); + + it('a model that fails to load is "unavailable" and is retried next time', async () => { + let attempts = 0; + const stt = new BuiltinWhisperStt({ + model: 'onnx-community/whisper-base', + dtype: 'q8', + cacheDir: '/nonexistent', + load: async () => { + attempts += 1; + if (attempts === 1) throw new Error('no network'); + return async () => ({ text: 'recovered' }); + }, + }); + await expect(stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: never })).rejects.toMatchObject({ kind: 'unavailable' }); + await new Promise((r) => setTimeout(r, 5)); + expect(await stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: never })).toBe('recovered'); + expect(attempts).toBe(2); + }); + + it('a model that throws on a recording is "failed", not a crash', async () => { + const { stt } = make(async () => { + throw new Error('bad tensor'); + }); + const err = await stt.transcribe({ pcm: tone(1), locale: 'en-US', signal: never }).catch((e) => e); + expect(err).toBeInstanceOf(SttError); + expect(err.kind).toBe('failed'); + }); +}); diff --git a/services/bridge/test/units.test.ts b/services/bridge/test/units.test.ts index a8f3817..b45cf44 100644 --- a/services/bridge/test/units.test.ts +++ b/services/bridge/test/units.test.ts @@ -7,7 +7,7 @@ import { mapRunStatus } from '../src/hermes/runsAdapter.ts'; import { RateLimiter } from '../src/ratelimit.ts'; import { pcmToWav } from '../src/stt/adapter.ts'; -const base = { HERMES_API_KEY: 'k', HERMEVEN_DB_PATH: ':memory:' }; +const base = { HERMES_API_KEY: 'k', HERMEVEN_DB_PATH: ':memory:', STT_PROVIDER: 'none' }; describe('configuration', () => { it('binds loopback by default and refuses a public bind without an explicit acknowledgement', () => { diff --git a/tests/integration/harness.ts b/tests/integration/harness.ts index 3dcd2d3..14646c8 100644 --- a/tests/integration/harness.ts +++ b/tests/integration/harness.ts @@ -68,7 +68,7 @@ export async function createHarness( HERMEVEN_ALLOWED_ORIGINS: 'https://app.example', HERMES_REQUEST_TIMEOUT_MS: '300', ...(opts.stt === false - ? {} + ? { STT_PROVIDER: 'none' } : { STT_PROVIDER: 'openai-compatible', STT_BASE_URL: stt.url, STT_API_KEY: stt.apiKey, STT_MODEL: 'fake-whisper' }), ...opts.env, }; diff --git a/tests/real-hermes/realHermes.test.ts b/tests/real-hermes/realHermes.test.ts index 38d281e..d6b7db4 100644 --- a/tests/real-hermes/realHermes.test.ts +++ b/tests/real-hermes/realHermes.test.ts @@ -126,6 +126,7 @@ beforeAll(async () => { HERMES_BASE_URL: hermesUrl, HERMES_API_KEY: API_KEY, HERMES_POLL_INTERVAL_MS: '100', + STT_PROVIDER: 'none', HERMEVEN_AGENT_DEADLINE_SECONDS: '60', HERMEVEN_CANCEL_GRACE_SECONDS: '30', }); diff --git a/tests/real-stt/fixtures/README.md b/tests/real-stt/fixtures/README.md new file mode 100644 index 0000000..4cd0dcd --- /dev/null +++ b/tests/real-stt/fixtures/README.md @@ -0,0 +1,9 @@ +# Speech fixture + +`jfk.wav`: 11 seconds of John F. Kennedy's 1961 inaugural address, 16 kHz mono 16-bit PCM. +A work of the United States government (public domain), taken from the sample set distributed +with whisper.cpp (`samples/jfk.wav`). Expected words: "ask not what your country can do for you, +ask what you can do for your country". + +It is a clean studio-quality recording. It says nothing about how well the glasses microphone, +a noisy street, or any particular accent will transcribe. diff --git a/tests/real-stt/fixtures/jfk.wav b/tests/real-stt/fixtures/jfk.wav new file mode 100644 index 0000000..3184d37 Binary files /dev/null and b/tests/real-stt/fixtures/jfk.wav differ diff --git a/tests/real-stt/realStt.test.ts b/tests/real-stt/realStt.test.ts new file mode 100644 index 0000000..a9a1c93 --- /dev/null +++ b/tests/real-stt/realStt.test.ts @@ -0,0 +1,100 @@ +import { readFileSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import { BuiltinWhisperStt } from '../../services/bridge/src/stt/builtinWhisper.ts'; +import { createHarness, type Harness } from '../integration/harness.ts'; + +/** + * REAL SPEECH-TO-TEXT. The bridge's built-in Whisper model, really loaded and really run on + * this machine's CPU, transcribing a real human speech recording that is uploaded through the + * bridge's HTTP API exactly as the glasses app uploads a capture. + * + * Still fake: Hermes (tests/fakes/fakeHermes.ts) and the glasses. The recording is a clean + * archive clip, not audio from a G2 microphone. + */ +const here = dirname(fileURLToPath(import.meta.url)); +const speech = readFileSync(resolve(here, 'fixtures/jfk.wav')).subarray(44); // strip the WAV header: raw PCM +let h: Harness; +let token: string; +let conversation: string; + +beforeAll(async () => { + h = await createHarness({ + stt: false, + env: { + STT_PROVIDER: 'builtin', + STT_CACHE_DIR: resolve(here, '.cache'), + HERMEVEN_CAPTURE_MAX_SECONDS: '30', + }, + timing: { transcribeDeadlineMs: 120_000, agentDeadlineMs: 30_000 }, + }); + expect(h.bridge.stt).toBeInstanceOf(BuiltinWhisperStt); + const started = Date.now(); + await (h.bridge.stt as BuiltinWhisperStt).warm(); + console.info(`[real-stt] model ${h.config.stt.model} (${h.config.stt.dtype}) loaded in ${Date.now() - started} ms; rss ${Math.round(process.memoryUsage().rss / 1e6)} MB`); + token = (await h.pair()).token; + conversation = await h.conversation(token); +}); + +afterAll(async () => { + await h?.close(); +}); + +describe('built-in Whisper speech-to-text', () => { + it('transcribes real speech uploaded as a capture and sends the words to the agent', async () => { + // Watch the event loop while the model runs: the bridge must stay responsive. + let worstLag = 0; + let last = performance.now(); + const probe = setInterval(() => { + const now = performance.now(); + worstLag = Math.max(worstLag, now - last - 20); + last = now; + }, 20); + + const res = await h.audioTurn(token, conversation, Buffer.from(speech)); + expect(res.status).toBe(202); + const health = await h.api('GET', '/healthz'); + expect(health.status).toBe(200); + const done = await h.waitTerminal(token, res.body.request_id, 120_000); + clearInterval(probe); + + console.info( + `[real-stt] ${(speech.length / 32000).toFixed(1)} s of speech transcribed in ${done.timings.transcribe_ms} ms; ` + + `worst event-loop stall ${Math.round(worstLag)} ms; rss ${Math.round(process.memoryUsage().rss / 1e6)} MB`, + ); + console.info(`[real-stt] transcript: ${JSON.stringify(done.input_text)}`); + expect(done.outcome).toBe('succeeded'); + const heard = (done.input_text ?? '').toLowerCase().replace(/[^a-z ]/g, ''); + expect(heard).toContain('ask not what your country can do for you'); + expect(heard).toContain('ask what you can do for your country'); + // The agent received exactly the transcript. + expect(h.hermes.lastRun()!.input).toBe(done.input_text); + expect(h.hermes.executions).toBe(1); + }); + + it('a silent capture is reported as "no speech" and never reaches the agent', async () => { + const before = h.hermes.executions; + const res = await h.audioTurn(token, conversation, Buffer.alloc(3 * 32000)); + const done = await h.waitTerminal(token, res.body.request_id, 60_000); + expect(done.outcome).toBe('failed'); + expect(done.error?.code).toBe('stt_empty'); + expect(h.hermes.executions).toBe(before); + }); + + it('a very quiet room-noise capture is also treated as no speech', async () => { + const noise = Buffer.alloc(3 * 32000); + for (let i = 0; i < noise.length / 2; i++) noise.writeInt16LE(Math.round((Math.random() - 0.5) * 40), i * 2); + const res = await h.audioTurn(token, conversation, noise); + const done = await h.waitTerminal(token, res.body.request_id, 60_000); + expect(done.error?.code).toBe('stt_empty'); + }); + + it('a second recording is transcribed with the model already warm', async () => { + const res = await h.audioTurn(token, conversation, Buffer.from(speech.subarray(0, 6 * 32000))); + const done = await h.waitTerminal(token, res.body.request_id, 120_000); + console.info(`[real-stt] warm: 6.0 s of speech in ${done.timings.transcribe_ms} ms -> ${JSON.stringify(done.input_text)}`); + expect(done.outcome).toBe('succeeded'); + expect((done.input_text ?? '').toLowerCase()).toContain('fellow americans'); + }); +}); diff --git a/tests/real-stt/vitest.config.ts b/tests/real-stt/vitest.config.ts new file mode 100644 index 0000000..3454a41 --- /dev/null +++ b/tests/real-stt/vitest.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config'; + +// Opt-in: runs the real built-in Whisper model on the CPU. The first run downloads the model. +export default defineConfig({ + test: { + name: 'real-stt', + root: new URL('../..', import.meta.url).pathname, + include: ['tests/real-stt/**/*.test.ts'], + testTimeout: 180_000, + hookTimeout: 600_000, + fileParallelism: false, + }, +});