It runs ONNX speech models (a FastConformer encoder with a CTC head and an attention decoder) through ONNX Runtime
and serves:
- `POST /v1/transcribe`: transcribe an uploaded audio file of any length (long files are cut at pauses into windows of
up to 30 s);
- `GET /stream`: live transcription over a WebSocket (needs a streaming model package);
- `GET /health`, `GET /help` (the full API, generated from what this server actually loaded) and `GET /demo` (a
browser page for uploads, microphone recording and live streaming).
The server ships no model weights. It downloads a model package from Hugging Face on first start, or loads one you
place yourself (see [Model files](#model-files)).
The models this server was built for, their training and their benchmark results are described in the
[technical report](https://arxiv.org/abs/2611.41102).
- [Quick start (Docker)](#quick-start-docker)
- [Deployment modes](#deployment-modes): Flash, Normal and Performance
- [Word boost (custom vocabulary)](#word-boost-custom-vocabulary)
- [Model files](#model-files): automatic download or manual placement
- [Installation without Docker](#installation-without-docker)
- [Configuration](#configuration)
- [API](#api)
- [Limitations](#limitations)
- [Security notes](#security-notes)
## Quick start (Docker)
```bash
git clone https://github.com/visai-ai/visai-openspeech-inference-server speech-server
cd speech-server
# CPU
docker build -f Dockerfile.cpu -t speech-server:cpu .
# GPU (needs the NVIDIA driver >= 535 and the NVIDIA Container Toolkit on the host)
docker build -f Dockerfile.gpu -t speech-server:gpu .
export SPEECH_API_KEY="$(openssl rand -hex 24)" # clients must send this key (at least 16 characters)
docker run --rm --gpus all -p 127.0.0.1:8000:8000 \
-e SPEECH_API_KEY -e MODEL_REPO=VISAI-AI/visai-openspeech-offline-flash-preview \
-v speech-models:/models speech-server:gpu
```
For the CPU image, drop `--gpus all` and use `speech-server:cpu`. The examples publish the port on 127.0.0.1 only:
plain HTTP carries the API key and the audio unencrypted, so for remote clients put a TLS reverse proxy in front (see
[Security notes](#security-notes)) rather than publishing the port on all interfaces. The first start downloads the model into the
`speech-models` volume; later starts reuse it. `-e NAME` without a value passes the variable from your shell, so
keys stay out of your shell history and the process list (anyone with access to the Docker daemon can still read a
container's environment with `docker inspect`).
Then:
```bash
curl -s http://127.0.0.1:8000/health
curl -s -H "Authorization: Bearer $SPEECH_API_KEY" --data-binary @audio.wav \
"http://127.0.0.1:8000/v1/transcribe?lang=th"
```
`docker compose --profile cpu up` (or `--profile gpu`) does the same with `docker-compose.yml`; put the variables in a
`.env` file next to it (and never commit that file). The compose file publishes the port on 127.0.0.1 only
(`BIND=0.0.0.0` to expose it), runs the container read-only without Linux capabilities, and keeps uploads in a
tmpfs.
## Deployment modes
The server has three ways to turn audio into text. They trade speed for accuracy; pick one per deployment, or serve
several on one port and choose per request with `?mode=`.
| | Flash mode | Normal mode (default) | Performance mode |
|---|---|---|---|
| What runs | encoder + CTC head | encoder + attention decoder, greedy | encoder + attention decoder, beam search |
| Settings | `MODES=ctc` (offline) or `MODES=ctc-stream` (streaming) | `MODES=decoder` | `MODES=decoder DECODE=beam BEAM=4`, or per request with `DECODES=greedy,beam` and `?decode=beam` |
| Speed | fastest | 1.1-1.4x slower than Flash | about 2x slower than Normal on GPU |
| Accuracy | lowest of the three | better than Flash | small further gain over Normal |
| Repetition loops | cannot happen | possible (see [Limitations](#limitations)) | possible, less often |
| Punctuation, number formatting (`pnc`, `itn`), timestamps | no `pnc` / `itn`; token timestamps | all | all |
Measured throughput of one model package (FastConformer, about 330 M parameters; Thai test audio, many files at once):
| | GPU (V100, fp16) | CPU (16 threads, fp32) |
|---|---|---|
| Flash (`ctc`) | about 2,600x real time | about 70x real time |
| Normal (`decoder`, greedy) | about 1,850x real time | about 62x real time |
| Performance (`decoder`, beam 4) | about 970x real time | slower; beam search is mainly for GPU |
Your numbers depend on the GPU / CPU, the batch settings and the audio. The GPU figures are for many requests batched
together; a single short request is dominated by fixed overhead (tens of milliseconds), so there the modes are much
closer (on an A100, five 7-15 s clips one at a time: Flash 0.23 s, Normal 0.65 s, Performance 0.73 s in total).
The GPU figures above come from a batch benchmark with fp16 graphs. The released model packages ship fp32 graphs.
[LOADTEST.md](LOADTEST.md) reports end-to-end throughput and latency of this server with them, on one V100 and on 8 CPU
cores, for files and live streams.

**Flash mode** decodes the CTC head directly: no decoder, so no loops and the lowest latency. With a streaming model
package, `ctc-stream` (and the live `/stream` WebSocket) gives partial results as audio arrives. The look-ahead
(`?lookahead=0|4|13`, in 80 ms frames) trades latency for accuracy: 0 is the fastest to react, 13 (about 1.1 s) the
most accurate.
**Normal mode** runs the attention decoder with plain greedy decoding (the most likely token at every step, no
heuristics). It is the default and the best balance for most uses. It can also write punctuation and case
(`?pnc=true`), numbers as digits (`?itn=true`) and segment timestamps.
**Performance mode** keeps the 4 (`BEAM`) best partial transcripts at every step. It is the most accurate setting
and the slowest; use it on a GPU when accuracy matters more than throughput.
Serving several modes on one port, for example `MODES=decoder,ctc`, lets each request choose (`?mode=ctc`); the first
mode is the default. Normal and Performance can be served side by side too: `DECODES=greedy,beam` (`--decodes`) loads
a second decoder engine (sharing the encoder) and each decoder request picks with `?decode=greedy` or `?decode=beam`
(the first listed is the default). A server for every setup:
`MODES=decoder,ctc,ctc-stream,dec-stream DECODES=greedy,beam` with a streaming package (`STREAM_MODEL_*`). With `SHARE_ENCODER=true` (the default) the modes, and the two decoder
searches, share one copy of the encoder, so this costs little extra memory: see [Encoder sharing](#encoder-sharing).
A streaming decoder mode (`dec-stream`, preview) is also available when the streaming package includes a streaming
decoder; see `GET /help`.
The demo page (`GET /demo`) shows these setups as a grid, Flash / Normal / Performance by offline / streaming, with
the combinations this server does not offer greyed out, and a word-boost box where the chosen setup supports it.
### Encoder sharing
The encoder is the largest part of the model. When one server runs both the decoder and CTC modes:
- `--share-encoder` / `SHARE_ENCODER=true` (default): one encoder session serves both modes; one copy of the encoder
weights in memory. CTC requests use the full encoder graph and ignore the decoder's inputs it also produces, so they
are slightly slower than with a dedicated CTC graph. The streaming modes (`ctc-stream`, `dec-stream`) likewise share
one streaming encoder. With `DECODES=greedy,beam`, the beam engine also reuses the greedy engine's encoder and the
decoder graphs both open (with word boost on, greedy already holds beam's top-k graphs).
- `--no-share-encoder` / `SHARE_ENCODER=false`: each mode loads its own encoder (CTC uses the lighter CTC-only graph,
unless word boost is on and the package has the `ctc_lp` graph: boosted CTC needs the full encoder's output).
Uses about one more encoder's worth of memory (measured on an A100 at fp16: about 1.8 GB for decoder + CTC shared,
2.5 GB unshared); CTC is a little faster.
`GET /health` reports `share_encoder`, and the start-up log names the engines that share an encoder.
## Word boost (custom vocabulary)
Callers can pass names, organisations or other terms that the transcript should spell correctly; decoding is then
biased toward them (shallow fusion). It is opt-in per request: without a list every mode decodes exactly as it does
by default.
```bash
curl -s -H "Authorization: Bearer $SPEECH_API_KEY" --data-binary @audio.wav \
"http://127.0.0.1:8000/v1/transcribe?mode=decoder&word_boost=Acme%20Corp&word_boost=Jane%20Doe&boost=1.2"
```
- `word_boost`: one phrase per parameter (repeat it), or one JSON list such as
`["Acme Corp", {"phrase": "Jane Doe", "boost": 1.5}]`. Up to 500 phrases per request, 100 on a live stream, 50
characters each. Phrases are matched by their text, however the tokenizer splits them, so Thai and Chinese phrases
need no spaces. Write each phrase as the transcript should show it.
- `boost` (greater than 0, at most 2; default 1): overall strength; a phrase's own `boost` multiplies it.
- `ctc_beam` (1-8, default 4; CTC modes): width of the boosted CTC beam search.
- Live streams (`/stream`, `ctc-stream`) take the same fields in the start message.
How each deployment mode applies it:
| Mode | Files (`POST /v1/transcribe`) | Live / streaming (`ctc-stream`, `/stream`) | Search while a list is active |
|---|---|---|---|
| Flash (`ctc`) | CTC prefix beam search with fusion (`ctc_beam`, default 4); `ctc_beam=1` is a cheaper greedy re-ranking | the same search frame by frame; partials are never revised: text is sent once every beam agrees on it, or after each chunk for all but the last 2 tokens of the best beam | beam 4 (1-8); plain greedy without a list |
| Normal (`decoder`, greedy) | fusion at every greedy step over the step's top 16 tokens | not available: `dec-stream` does not take word boost yet | greedy |
| Performance (`decoder`, beam) | fusion inside the beam search | not available | beam (`BEAM`) |
What it needs from the model package: CTC modes need the `ctc_lp` graph (CTC log-probabilities; `ctc-stream` needs
it in the streaming package), decoder modes need the decoder's top-k graphs (`dec_prefill_topk`, `dec_lean_topk`)
and `gather`. A mode whose package lacks them refuses `word_boost` with a 400 that says so, and `GET /help` lists the
modes that can boost. `--no-word-boost` (`WORD_BOOST=false`) turns the feature off.
Behaviour and limits:
- The bonus only re-ranks tokens among a frame's or step's top candidates (8 for CTC, 16 for the decoder), so it
helps most where the model hesitates between spellings; it can still write a listed phrase where the model gave it
a modest probability, which is why lists should be short and the strength tuned. The end of the transcript gets no
bonus and a bonus never makes the model end early; in greedy decoding an ending the model chose is always kept (a
beam search lets hypotheses compete on fused scores). The CTC blank gets no bonus
either, but in the CTC beam search a phrase's bonus can win over a blank the model preferred: that is how a
boosted phrase gets written, and also how false insertions happen.
- A phrase earns its bonus from its second token on (the model has to start it by itself); a partial match that
breaks gives its bonus back; each phrase is boosted at most 3 times per 30 s window (offline) or per stream. A
phrase that is a single token of the vocabulary is therefore not boosted.
- Output changes only where a listed phrase is written: offline (`decoder`, `ctc`, `ctc-stream` uploads), a window
in which the boosted search completes no listed phrase returns exactly the default output. Live `/stream` sessions
cannot take text back, so there a list can change the text slightly even where no phrase is said (the boosted
beam search, and at most the last 2 tokens are held back until the next chunk). In decoder mode, a batch in which
some window writes no listed phrase is decoded a second time with the default search.
- The strength defaults are starting points, not tuned values: measure on your own development data (recall of the
listed phrases, false insertions on audio that does not contain them, overall error rate) before raising `boost`.
Keep lists short: the words the model gets wrong, not every word you expect.
- Boosting can make a decoder write a listed phrase where something similar was said, and it interacts with the
decoder's repetition failure mode (see [Limitations](#limitations)); the per-phrase cap limits, but does not rule
out, a boosted phrase being repeated.
- Cost: the boosted searches run on the host in Python; expect a few milliseconds to a few tens of milliseconds per
second of audio on CPU, more for larger beams; a window that writes no listed phrase is decoded a second time
with the default search. On GPU, boosted requests also run the CTC log-probability graph (CTC modes) or the top-k
decoder graphs (decoder modes). Memory: with word boost on (the default),
decoder engines also load the top-k decoder graphs (unless a beam engine already has them) and CTC engines the
small `ctc_lp` graph; compiled lists are cached (bounded); `--no-word-boost` avoids all of it.
- A listed phrase that is a suffix of a longer listed phrase is only boosted where it starts a match of its own.
- Token timestamps with word boost: in `ctc`, the boosted tokens are force-aligned to the CTC log-probabilities
(`token_times` is empty if no alignment exists); in `ctc-stream` with a beam, a token's start / end are the frame
it was committed at, not the frames it was spoken in.
## Model files
A model package is a directory with `spec.json`, `tokenizer.model`, `mel_stats.json` and the ONNX graphs that
`spec.json` lists (the encoder, CTC and decoder graphs; streaming packages add a front-end graph and chunk-encoder
graphs). A package may be trimmed to the graphs one deployment needs; the server stops at start-up, naming the file,
if a mode you asked for needs a graph that is not there.
Offline packages (decoder / ctc) and streaming packages (ctc-stream / dec-stream and the live WebSocket) are separate:
an offline package cannot stream. To serve both, give one of each (`MODEL_*` and `STREAM_MODEL_*`).
The published packages, with setups, results and license on their model cards:
| Package | Hugging Face repository | Set as |
|---|---|---|
| Offline (`decoder`, `ctc`) | [VISAI-AI/visai-openspeech-offline-flash-preview](https://huggingface.co/VISAI-AI/visai-openspeech-offline-flash-preview) | `MODEL_REPO` |
| Streaming (`ctc-stream`, `dec-stream`) | [VISAI-AI/visai-openspeech-streaming-flash-preview](https://huggingface.co/VISAI-AI/visai-openspeech-streaming-flash-preview) | `STREAM_MODEL_REPO` |
### Option 1: automatic download from Hugging Face
Set the repository. The model repositories are public, so no account or token is needed:
```bash
export MODEL_REPO=VISAI-AI/visai-openspeech-offline-flash-preview # offline model (decoder / ctc)
export STREAM_MODEL_REPO=VISAI-AI/visai-openspeech-streaming-flash-preview # optional: streaming model
export MODEL_REVISION=main # optional: branch, tag or commit to pin
python -m speech_server serve # or the Docker command above
```
The files are downloaded once into `MODEL_CACHE` (default `~/.cache/speech-server`; `/models` in the Docker images,
which you should mount as a volume) under `