> ## Documentation Index
> Fetch the complete documentation index at: https://joe-pro-ai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> How audio becomes a transcript, a card, a claim check, and a topic ledger, and which model handles each step.

Sluice Box is a FastAPI server on `127.0.0.1:7788` with a WebSocket to a single local page. Everything runs on your PC except the model calls.

## The whole path

```mermaid theme={"dark"}
flowchart TD
  A["Windows loopback or microphone<br/>(explicit Start listening)"] --> G["Speech gate<br/>amplitude VAD, 650 ms silence,<br/>20 s max segment"]
  P["Pasted or typed turn"] --> L
  R["scripts/demo_replay.py<br/>POST /replay"] --> S
  G --> S{"STT_BACKEND"}
  S -- "meta" --> M["Muse Voice Transcribe<br/>wss /asr/realtime, DIARIZATION<br/>default, 0.0% WER on the hard clip"]
  S -- "openvino" --> W["OpenVINO Whisper on this PC<br/>e.g. whisper-large-v3-turbo"]
  M -- "fails" --> W
  M --> L["Transcript ledger<br/>timestamped turn refs"]
  W --> L
  L --> N["Notes retrieval<br/>notes/ folder, optional GBrain URL"]
  N --> C["Live card<br/>Muse Spark Open via OpenRouter<br/>meta/muse-spark-open + input_audio WAV"]
  C -- "OpenRouter down" --> O["Ollama gemma3:4b<br/>offline fallback"]
  C --> T["Topic Ledger<br/>merge, dedupe, mark said"]
  T -- "20 s idle or Expand" --> X["Expansion<br/>Muse Spark Open, capped"]
  C -- "Check this claim" --> F["Muse Spark 1.3<br/>Meta Model API /responses + web_search<br/>live, about $0.03 a check"]
  F -- "fails, META_STRICT=1" --> E["Error card with the Meta error code"]
  F -- "fails, META_STRICT=0" --> D["OpenRouter deep model<br/>card says who answered"]
  T --> J["sessions/*.json and Export .md"]
  classDef muse fill:#1a1503,stroke:#F5B700,stroke-width:2px,color:#EAF4F2
  classDef meta fill:#0a1020,stroke:#5B8CFF,stroke-width:2px,color:#EAF4F2
  classDef local fill:#06201d,stroke:#19C3B1,stroke-width:2px,color:#EAF4F2
  class C,X muse
  class M,F meta
  class E local
  class W,O,G,L,N,T,J local
```

Gold nodes are Muse Spark Open on OpenRouter. Blue nodes are the Meta Model API (Muse Voice Transcribe and Muse Spark 1.3), both live. Teal nodes run on your PC.

## Speech to text

Audio is captured with `pyaudiowpatch` from the device you pick. An amplitude speech gate cuts a segment after 650 ms of silence, or at 20 seconds of continuous speech. The segment is resampled to 16 kHz mono and held in memory only.

> [tab] OpenVINO Whisper (local)
>
> `STT_BACKEND=openvino` runs any OpenVINO Whisper export from `WHISPER_MODEL_DIR` through `optimum-intel`, on CPU by default (`WHISPER_DEVICE` overrides). The model is compiled once per folder and cached. The processor is loaded from the model folder, so large-v3 and turbo exports such as `whisper-large-v3-turbo` get the 128 mel bins they need instead of the tiny model's 80.
>
> This is the fallback when Muse Voice Transcribe fails or `spend_cap_reached` is hit, and the main engine if you choose `openvino`.

> [tab] Muse Voice Transcribe (Meta)
>
> `STT_BACKEND=meta` (the default in the Meta profile) opens `wss://api.meta.ai/v1/asr/realtime` with model `muse-voice-transcribe-1.0` in `DIARIZATION` mode. The key travels in the first JSON message, then 16 kHz PCM frames follow. Speaker labels become `Speaker 1`, `Speaker 2`, and you can rename them on the card. Replayed files use `POST /v1/asr/transcribe` as multipart with a `request` JSON part and an `audio` part.
>
> If a Meta call fails, the desk shows `stt: whisper (meta failed: <reason>)` and falls back to local Whisper when a model folder is set.

### Measured accuracy

Measured on Joe's PC on Nov 3, 2026 with `scripts/stt_compare.py`. Both engines get the same replay segments, the same reference text and the same normalisation.

| Clip | Muse Voice Transcribe | OpenVINO Whisper large-v3-turbo |
| - | - | - |
| `sluice-hard.wav` (58 words: names, a date, decimals, a hyphenated surname) | **0.0%** | 5.2% ("14th" as "14", "Osei-Bonsu" as "Osebansu") |
| `sluice-demo.wav` (25 words) | 8.0% ("emission", a doubled "purple") | **0.0%** |
| Both clips (83 words) | **2.4%** | 3.6% |

Muse Voice Transcribe is the default (`STT_BACKEND=meta`) and Whisper is the fallback. Transcribing the 35 seconds of test audio cost about \$0.002.

### Spend cap

Every Meta call (claim checks, file and streaming transcription) appends one line to `sessions/meta-spend.jsonl` with its tokens, searches or audio seconds and an estimated cost from Meta's published prices. Once the total reaches `META_SPEND_CAP_USD` (default \$5), Meta calls are refused with `spend_cap_reached`, Whisper takes over speech, and `/health` shows `meta_spend_usd` against the cap.

## The live card: Muse Spark Open

In the Meta profile every turn goes to `meta/muse-spark-open` on OpenRouter. When the desk heard the turn, the request carries the transcript plus up to the last 20 seconds of that turn's audio as a base64 WAV content part:

```json Chat Completions content part theme={"dark"}
{ "type": "input_audio", "input_audio": { "data": "<base64 wav>", "format": "wav" } }
```

The request streams, uses `max_tokens` 1200, and asks for a JSON object. With JSON mode on, provider routing sets `require_parameters: true` and sorts by latency, so a provider that would ignore `response_format` is skipped. A rejected format is retried once without it.

The client tries three request shapes and caches the one that works: Chat Completions with audio, then the OpenRouter Responses API with audio, then text only. The provenance line shows the result, for example `Muse Spark Open, heard audio` or `Muse Spark Open, audio off`. Audio token usage reported by the provider is the evidence that audio was taken in.

If OpenRouter cannot be reached, the live card falls back to Ollama (`gemma3:4b`) on the PC.

## Check this claim: Muse Spark 1.3

> [!TIP]
>
> Live. On Nov 3, 2026, "Everyone knows the Great Wall of China is visible from the Moon with the naked eye" came back **false** in 26 s, citing [Scientific American](https://www.scientificamerican.com/article/is-chinas-great-wall-visible-from-space/) and [phys.org](https://phys.org/news/2005-05-china-wall-great-view-space.html). It ran 3 searches and used 16,706 input and 2,485 output tokens, about \$0.03.

A click on **Check this claim** sends one claim to `POST https://api.meta.ai/v1/responses` with model `muse-spark-1.3`, the `web_search` tool (`search_context_size: medium`), `include: ["web_search_call.results"]`, and a `text.format` JSON schema. The desk collects every URL that search returned for that request. A citation is kept only if it exactly matches one of those URLs. If search returned nothing, a `verified` claim is downgraded to `unverified`.

The verdict label follows the evidence. `false` means retrieved sources refute the claim and `verified` means they support it; either one needs every citation to be a retrieved URL, or it falls back to `contested`. `contested` is kept for real disagreement between sources. Muse Spark 1.3 sometimes cites opaque `【id†L2-L3】` markers, so those are dropped and the pages it opened with `open_page` are cited instead. Its short `commentary` messages between searches are skipped, and only the final answer is parsed. Provenance reads like `Muse Spark 1.3, 3 web sources`.

Claim checks are capped by `FACT_CHECK_MAX_CHARS` (2000) and `FACT_CHECK_PER_MINUTE` (6).

## META\_STRICT

`META_STRICT` decides what happens when a Meta call fails. It defaults to on in the Meta profile and off otherwise.

| `META_STRICT` | Muse Spark 1.3 fails | What the card says |
| - | - | - |
| on (Meta profile default) | No other model answers. | `Unsure. Muse Spark 1.3 unavailable: spend_cap_reached. META_STRICT is on, so no other model answered.` |
| off | The OpenRouter deep model answers, if an OpenRouter key is set. | `Muse Spark 1.3 unavailable: <reason>; answered by <model>` |

The reason shown is short and redacted: the Meta `error.code` first, then `error.message`, then `error.type`, then the HTTP status. API keys are scrubbed from every logged or displayed error. A Meta demo therefore never shows a non-Meta answer while looking like Muse.

## Evidence policy

* A transcript is a record of what was heard, not proof it is true.
* Notes are labeled `Your notes` and linked to their file and heading. GBrain hits are labeled `Your memory`.
* A fact is `verified` only when it cites one of those retrieved sources exactly, or a URL search returned for that claim. A substring of a note is not enough. Anything else is removed and the card says it is unsure.

## Local server surface

| Route | Purpose |
| - | - |
| `GET /` and `GET /desk.js` | The desk page |
| `GET /health` | Profile, models, STT backend, notes count, Topic Ledger caps. No keys. |
| `GET /audio-devices` | Input and loopback devices |
| `POST /listen/{source_index}`, `POST /stop-listening` | Start and stop capture. Stop transcribes the last partial segment first. |
| `POST /transcribe-now` | Send the audio heard so far to STT now. `409` when not listening. |
| `POST /listen-file` | Play a WAV through the live pipeline at real speed |
| `GET /turns` | The session's turns so far, for a reloaded page |
| `POST /transcript` | Paste a turn |
| `POST /fact-check` | Check this claim |
| `POST /replay` | Replay a WAV |
| `POST /speak` | Hear this (ElevenLabs, click only) |
| `GET /topics`, `POST /topics/expand` | Topic Ledger snapshot and expansion |
| `POST /topics/{topic_id}/points/{point_id}/said` | Mark a point said or unsaid |
| `GET /topics/export.md` | Download the ledger as markdown |
| `WS /ws` | Status, transcript, card, and topic events |

The WebSocket and the transcript, fact-check, replay, transcribe-now, listen-file, speak, and Topic Ledger write routes reject any `Origin` not in `ALLOWED_ORIGINS`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.