Build speech-to-text into the bridge; add droplet deployment examples
STT_PROVIDER now defaults to "builtin": Whisper (onnx-community/whisper-base, q8) runs in the bridge process on the CPU via @huggingface/transformers, so no provider account is needed and recordings stay on the bridge host. Silent captures are detected by level before the model runs. The external OpenAI-compatible adapter remains available. Tests: 130 unit/integration; 4 scenarios with the real model on a real speech recording (npm run test:real-stt). Not tested on audio from the glasses or on a droplet. deploy/ and docs/deploy-droplet.md are examples that have not been run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
+11
-3
@@ -23,9 +23,17 @@ HERMEVEN_DB_PATH=./data/hermeven.sqlite
|
|||||||
# Read the real value from Diagnostics -> "Page origin" in the phone page.
|
# Read the real value from Diagnostics -> "Page origin" in the phone page.
|
||||||
HERMEVEN_ALLOWED_ORIGINS=
|
HERMEVEN_ALLOWED_ORIGINS=
|
||||||
|
|
||||||
# --- Speech-to-text (optional; typed questions work without it) --------------
|
# --- Speech-to-text -----------------------------------------------------------
|
||||||
# "none" or "openai-compatible" (any server with POST {base}/audio/transcriptions).
|
# "builtin" (default): Whisper runs inside the bridge on the CPU. No account, and recordings
|
||||||
STT_PROVIDER=none
|
# 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_BASE_URL=https://stt.example/v1
|
||||||
# STT_API_KEY=replace-with-your-stt-key
|
# STT_API_KEY=replace-with-your-stt-key
|
||||||
# STT_MODEL=whisper-1
|
# STT_MODEL=whisper-1
|
||||||
|
|||||||
@@ -15,3 +15,4 @@ coverage/
|
|||||||
tests/simulator/.artifacts/
|
tests/simulator/.artifacts/
|
||||||
tests/real-hermes/.artifacts/
|
tests/real-hermes/.artifacts/
|
||||||
dist-manifest/
|
dist-manifest/
|
||||||
|
tests/real-stt/.cache/
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ small bridge between the two.
|
|||||||
| Path | State |
|
| Path | State |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Client, bridge and contract | Implemented. |
|
| 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. |
|
| Client in Even's official simulator | Passing (6 scenarios). Simulator only. |
|
||||||
| Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. |
|
| 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.** |
|
| Real model, real tools, approval flow | **Not run.** |
|
||||||
| Physical G2, ring, locked-phone use, battery | **Not run.** See `docs/device-test-plan.md`. |
|
| 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)
|
G2 <-Bluetooth-> Even phone app (WebView: apps/even-client)
|
||||||
| HTTPS + device credential
|
| 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
|
your Hermes API server
|
||||||
```
|
```
|
||||||
@@ -75,6 +76,7 @@ npm run typecheck
|
|||||||
npm test # unit and integration, fakes only
|
npm test # unit and integration, fakes only
|
||||||
npm run test:simulator # opens Even's simulator window
|
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-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`.
|
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/bridge-api.md` | The bridge contract. |
|
||||||
| `docs/security.md` | Threat model, controls, known gaps. |
|
| `docs/security.md` | Threat model, controls, known gaps. |
|
||||||
| `docs/setup.md` | Running, building, operating. |
|
| `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/device-test-plan.md` | The physical-device checklist. Not yet run. |
|
||||||
| `docs/test-evidence.md` | Commands run and their real results. |
|
| `docs/test-evidence.md` | Commands run and their real results. |
|
||||||
| `docs/decisions/` | Decision records. |
|
| `docs/decisions/` | Decision records. |
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -6,7 +6,7 @@ G2 mic / touch / HUD
|
|||||||
Even phone app -- WebView running apps/even-client (public Even Hub SDK)
|
Even phone app -- WebView running apps/even-client (public Even Hub SDK)
|
||||||
| HTTPS, device credential, polling
|
| HTTPS, device credential, polling
|
||||||
services/bridge (Fastify + SQLite)
|
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
|
|-- Hermes adapter --> Hermes API server (Runs API) for one configured profile
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ exactly in `apps/even-client/package.json`.
|
|||||||
| Vite / Vitest | 8.3.8 / 5.1.1 |
|
| Vite / Vitest | 8.3.8 / 5.1.1 |
|
||||||
| Fastify / @fastify/cors | 5.12.8 / 11.4.3 |
|
| Fastify / @fastify/cors | 5.12.8 / 11.4.3 |
|
||||||
| better-sqlite3 | 13.2.0 |
|
| 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 |
|
| @sinclair/typebox | 0.34.52 |
|
||||||
| pino | 10.4.0 |
|
| pino | 10.4.0 |
|
||||||
|
|
||||||
|
|||||||
@@ -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://<droplet-ip>: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.
|
||||||
+10
-6
@@ -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". |
|
| 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
|
Decision (updated after Dan asked for speech-to-text to be built in and to run on a droplet):
|
||||||
`POST /audio/transcriptions` contract (hosted or self-hosted Whisper). It is exercised only
|
the bridge runs OpenAI's Whisper model itself, on the CPU, through ONNX Runtime
|
||||||
against a test fake so far. **No real STT provider has been run**; none was available on the
|
(`@huggingface/transformers` 4.3.2, model `onnx-community/whisper-base`, 8-bit weights). No
|
||||||
development machine and choosing a paid one is Dan's decision (see "Decisions needed").
|
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
|
### 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`.
|
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.
|
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
|
2. ~~STT provider.~~ Decided 2026-11-18: built into the bridge.
|
||||||
(free, needs a machine). The adapter is the same either way.
|
|
||||||
3. **Target Hermes.** Which deployment and profile the bridge should point at, and a safe
|
3. **Target Hermes.** Which deployment and profile the bridge should point at, and a safe
|
||||||
read-only test profile for the first real run.
|
read-only test profile for the first real run.
|
||||||
4. **Distribution model**, given the per-build network whitelist: one build per deployment, or a
|
4. **Distribution model**, given the per-build network whitelist: one build per deployment, or a
|
||||||
|
|||||||
@@ -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` |
|
| 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. |
|
| 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 |
|
| Branch | `feat/vertical-slice-1`, local only |
|
||||||
| Head under review | `4687cc01147e2167997aa6a252343933070fbebd` |
|
| First slice | `4687cc01147e2167997aa6a252343933070fbebd` |
|
||||||
| Pushed | No. Nothing has been pushed; there is no PR. Pushing and merging are Dan's. |
|
| 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"). |
|
||||||
| Follow-up commit | The commit that adds this file and `docs/test-evidence.md` changes documentation only. |
|
| 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
|
Repository instructions: there were none to follow (no `AGENTS.md`, `CLAUDE.md`, `README` or
|
||||||
`CONTRIBUTING` existed). The kickoff specification was the only instruction source.
|
`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
|
## Changed files
|
||||||
|
|
||||||
Everything is new. 79 files at the head above.
|
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 ci` | clean install, 0 vulnerabilities reported |
|
||||||
| `npm run typecheck` | exit 0 |
|
| `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:simulator` | 6 passed, 0 failed; 10 consecutive runs of the final revision |
|
||||||
| `npm run test:real-hermes` | 9 passed, 0 failed |
|
| `npm run test:real-hermes` | 9 passed, 0 failed |
|
||||||
| `npm run client:build` | built; bundle searched for server secrets, none |
|
| `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 |
|
| Fakes only | 122 tests |
|
||||||
| Even simulator 0.9.5 | 6 scenarios, screenshots in `docs/evidence/simulator/` |
|
| Even simulator 0.9.5 | 6 scenarios, screenshots in `docs/evidence/simulator/` |
|
||||||
| Real Hermes v0.23.1, stub model | 9 scenarios |
|
| 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 |
|
| Real model or tools | none |
|
||||||
| Physical device | **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 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 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 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
|
## Blockers and open decisions
|
||||||
|
|
||||||
| # | Item | Owner |
|
| # | Item | Owner |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| 1 | Run `docs/device-test-plan.md`, starting with A13 (locked phone, pocket). | Dan |
|
| 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 |
|
| 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 |
|
| 5 | Independent architecture and security review of the head above. | Cody |
|
||||||
| 6 | Distribution model given Even's per-build network whitelist. | Dan, later |
|
| 6 | Distribution model given Even's per-build network whitelist. | Dan, later |
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -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.
|
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
|
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.
|
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
|
3. **Audio leaves the phone for the bridge host.** With the default built-in speech model it
|
||||||
self-hosted Whisper endpoint avoids this. The provider's own retention is outside our control.
|
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
|
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
|
does the same is unknown and is on the device checklist. If it does, recordings would be
|
||||||
visible to whoever can read that console.
|
visible to whoever can read that console.
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,8 @@
|
|||||||
# Setup
|
# Setup
|
||||||
|
|
||||||
Requirements: Node.js 22.13 or later, a Hermes install with the API server enabled, and (for
|
Requirements: Node.js 22.13 or later and a Hermes install with the API server enabled. Speech
|
||||||
voice) an OpenAI-compatible transcription endpoint.
|
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
|
```sh
|
||||||
npm ci
|
npm ci
|
||||||
@@ -98,4 +99,5 @@ npm run typecheck
|
|||||||
npm test # unit + integration, fakes only
|
npm test # unit + integration, fakes only
|
||||||
npm run test:simulator # needs a desktop session; opens the simulator window
|
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-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
|
||||||
```
|
```
|
||||||
|
|||||||
+54
-4
@@ -1,6 +1,8 @@
|
|||||||
# Test evidence
|
# 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.
|
These are the results of commands that were actually run. Nothing here is device evidence.
|
||||||
|
|
||||||
## What kind of evidence each suite is
|
## 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 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: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-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
|
## Results
|
||||||
|
|
||||||
@@ -25,8 +28,8 @@ Exit 0, no diagnostics, for contracts, bridge, client and tests.
|
|||||||
|
|
||||||
```
|
```
|
||||||
$ npm test
|
$ npm test
|
||||||
Test Files 7 passed (7)
|
Test Files 8 passed (8)
|
||||||
Tests 122 passed (122)
|
Tests 130 passed (130)
|
||||||
```
|
```
|
||||||
|
|
||||||
Run after a clean `npm ci`. Six consecutive full runs were green after the fix described under
|
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 |
|
| `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/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/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/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 |
|
| `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;
|
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.
|
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
|
### 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.
|
- A physical G2, the R1 ring, the Even phone app, any phone.
|
||||||
- The microphone with the phone locked or the app in the background.
|
- 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.
|
- A real language model, real tools, a real approval prompt.
|
||||||
- Hermes `waiting_for_approval`, `unknown`, `interrupted` and stopped-short runs against real
|
- Hermes `waiting_for_approval`, `unknown`, `interrupted` and stopped-short runs against real
|
||||||
Hermes (fake only).
|
Hermes (fake only).
|
||||||
|
|||||||
Generated
+915
-6
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -23,7 +23,8 @@
|
|||||||
"bridge:cli": "npm run -w @hermeven/bridge cli --",
|
"bridge:cli": "npm run -w @hermeven/bridge cli --",
|
||||||
"client:dev": "npm run -w @hermeven/even-client dev --",
|
"client:dev": "npm run -w @hermeven/even-client dev --",
|
||||||
"client:build": "npm run -w @hermeven/even-client build",
|
"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": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.19.0",
|
"@types/node": "^22.19.0",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^11.4.3",
|
"@fastify/cors": "^11.4.3",
|
||||||
"@hermeven/contracts": "*",
|
"@hermeven/contracts": "*",
|
||||||
|
"@huggingface/transformers": "^4.3.2",
|
||||||
"@sinclair/typebox": "^0.34.52",
|
"@sinclair/typebox": "^0.34.52",
|
||||||
"better-sqlite3": "^13.2.0",
|
"better-sqlite3": "^13.2.0",
|
||||||
"fastify": "^5.12.8",
|
"fastify": "^5.12.8",
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import type { HermesAdapter } from './hermes/adapter.ts';
|
|||||||
import { HermesRunsAdapter } from './hermes/runsAdapter.ts';
|
import { HermesRunsAdapter } from './hermes/runsAdapter.ts';
|
||||||
import { buildServer } from './server.ts';
|
import { buildServer } from './server.ts';
|
||||||
import { NoSttAdapter, type SttAdapter } from './stt/adapter.ts';
|
import { NoSttAdapter, type SttAdapter } from './stt/adapter.ts';
|
||||||
|
import { BuiltinWhisperStt } from './stt/builtinWhisper.ts';
|
||||||
import { OpenAiCompatibleStt } from './stt/openaiCompatible.ts';
|
import { OpenAiCompatibleStt } from './stt/openaiCompatible.ts';
|
||||||
import { TurnEngine, type EngineLog, type EngineTiming } from './turns.ts';
|
import { TurnEngine, type EngineLog, type EngineTiming } from './turns.ts';
|
||||||
|
|
||||||
export interface Bridge {
|
export interface Bridge {
|
||||||
app: FastifyInstance;
|
app: FastifyInstance;
|
||||||
|
stt: SttAdapter;
|
||||||
db: Db;
|
db: Db;
|
||||||
devices: Devices;
|
devices: Devices;
|
||||||
engine: TurnEngine;
|
engine: TurnEngine;
|
||||||
@@ -35,6 +37,9 @@ export function sttFromConfig(config: BridgeConfig): SttAdapter {
|
|||||||
if (config.stt.provider === 'openai-compatible') {
|
if (config.stt.provider === 'openai-compatible') {
|
||||||
return new OpenAiCompatibleStt({ baseUrl: config.stt.baseUrl, apiKey: config.stt.apiKey, model: config.stt.model });
|
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();
|
return new NoSttAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +75,7 @@ export async function createBridge(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
app,
|
app,
|
||||||
|
stt,
|
||||||
db,
|
db,
|
||||||
devices,
|
devices,
|
||||||
engine,
|
engine,
|
||||||
|
|||||||
@@ -22,10 +22,14 @@ export interface BridgeConfig {
|
|||||||
requestTimeoutMs: number;
|
requestTimeoutMs: number;
|
||||||
};
|
};
|
||||||
stt: {
|
stt: {
|
||||||
provider: 'none' | 'openai-compatible';
|
provider: 'none' | 'builtin' | 'openai-compatible';
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
|
/** Hub model id for `builtin`; provider model name for `openai-compatible`. */
|
||||||
model: string;
|
model: string;
|
||||||
|
/** `builtin` only: weight precision and where model files are cached. */
|
||||||
|
dtype: string;
|
||||||
|
cacheDir: string;
|
||||||
};
|
};
|
||||||
limits: {
|
limits: {
|
||||||
captureMaxSeconds: number;
|
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}`);
|
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'];
|
// Built-in Whisper is the default: voice works with no provider account and no audio
|
||||||
if (sttProvider !== 'none' && sttProvider !== 'openai-compatible') {
|
// leaving the bridge host.
|
||||||
throw new ConfigError('STT_PROVIDER must be "none" or "openai-compatible"');
|
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 = '';
|
let sttBaseUrl = '';
|
||||||
if (sttProvider === 'openai-compatible') {
|
if (sttProvider === 'openai-compatible') {
|
||||||
@@ -154,7 +168,9 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
|
|||||||
provider: sttProvider,
|
provider: sttProvider,
|
||||||
baseUrl: sttBaseUrl,
|
baseUrl: sttBaseUrl,
|
||||||
apiKey: env.STT_API_KEY || '',
|
apiKey: env.STT_API_KEY || '',
|
||||||
model: env.STT_MODEL || '',
|
model: sttModel,
|
||||||
|
dtype: sttDtype,
|
||||||
|
cacheDir: env.STT_CACHE_DIR || './data/models',
|
||||||
},
|
},
|
||||||
limits: {
|
limits: {
|
||||||
captureMaxSeconds,
|
captureMaxSeconds,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { LOG_REDACT, createBridge } from './app.ts';
|
import { LOG_REDACT, createBridge } from './app.ts';
|
||||||
import { ConfigError, loadConfig } from './config.ts';
|
import { ConfigError, loadConfig } from './config.ts';
|
||||||
import { loadEnvFile } from './env.ts';
|
import { loadEnvFile } from './env.ts';
|
||||||
|
import { BuiltinWhisperStt } from './stt/builtinWhisper.ts';
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
loadEnvFile();
|
loadEnvFile();
|
||||||
@@ -10,6 +11,17 @@ async function main(): Promise<void> {
|
|||||||
});
|
});
|
||||||
await bridge.app.listen({ host: config.host, port: config.port });
|
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;
|
let closing = false;
|
||||||
const stop = (signal: string) => {
|
const stop = (signal: string) => {
|
||||||
if (closing) return;
|
if (closing) return;
|
||||||
|
|||||||
@@ -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<Recognizer>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Recognizer = (audio: Float32Array, options: Record<string, unknown>) => 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<Recognizer> | null = null;
|
||||||
|
/** One transcription at a time: the model is CPU-bound and this is a single-user bridge. */
|
||||||
|
private queue: Promise<unknown> = 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<void> {
|
||||||
|
await this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private load(): Promise<Recognizer> {
|
||||||
|
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<Recognizer> {
|
||||||
|
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<string> {
|
||||||
|
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<string, unknown> = 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<string>((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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<string, unknown> }> = [];
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -7,7 +7,7 @@ import { mapRunStatus } from '../src/hermes/runsAdapter.ts';
|
|||||||
import { RateLimiter } from '../src/ratelimit.ts';
|
import { RateLimiter } from '../src/ratelimit.ts';
|
||||||
import { pcmToWav } from '../src/stt/adapter.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', () => {
|
describe('configuration', () => {
|
||||||
it('binds loopback by default and refuses a public bind without an explicit acknowledgement', () => {
|
it('binds loopback by default and refuses a public bind without an explicit acknowledgement', () => {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export async function createHarness(
|
|||||||
HERMEVEN_ALLOWED_ORIGINS: 'https://app.example',
|
HERMEVEN_ALLOWED_ORIGINS: 'https://app.example',
|
||||||
HERMES_REQUEST_TIMEOUT_MS: '300',
|
HERMES_REQUEST_TIMEOUT_MS: '300',
|
||||||
...(opts.stt === false
|
...(opts.stt === false
|
||||||
? {}
|
? { STT_PROVIDER: 'none' }
|
||||||
: { STT_PROVIDER: 'openai-compatible', STT_BASE_URL: stt.url, STT_API_KEY: stt.apiKey, STT_MODEL: 'fake-whisper' }),
|
: { STT_PROVIDER: 'openai-compatible', STT_BASE_URL: stt.url, STT_API_KEY: stt.apiKey, STT_MODEL: 'fake-whisper' }),
|
||||||
...opts.env,
|
...opts.env,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ beforeAll(async () => {
|
|||||||
HERMES_BASE_URL: hermesUrl,
|
HERMES_BASE_URL: hermesUrl,
|
||||||
HERMES_API_KEY: API_KEY,
|
HERMES_API_KEY: API_KEY,
|
||||||
HERMES_POLL_INTERVAL_MS: '100',
|
HERMES_POLL_INTERVAL_MS: '100',
|
||||||
|
STT_PROVIDER: 'none',
|
||||||
HERMEVEN_AGENT_DEADLINE_SECONDS: '60',
|
HERMEVEN_AGENT_DEADLINE_SECONDS: '60',
|
||||||
HERMEVEN_CANCEL_GRACE_SECONDS: '30',
|
HERMEVEN_CANCEL_GRACE_SECONDS: '30',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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.
|
||||||
Binary file not shown.
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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,
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user