Skip to content

feat(server): let Bazarr fetch subtitles from akou, by answering its whisper /asr and /detect-language - #396

Merged
GeiserX merged 5 commits into
mainfrom
feat/server-bazarr
Oct 11, 2026
Merged

GeiserX merged 5 commits into
mainfrom
feat/server-bazarr

Conversation

@GeiserX

@GeiserX GeiserX commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Bazarr cannot get subtitles from akou today. Its Whisper provider sends POST {endpoint}/asr with raw 16 kHz mono s16le PCM in one audio_file part, no key and User-Agent: Subliminal/2.1, and POST {endpoint}/detect-language with the whole track. akou has neither route, GET /v1/server hardcodes capabilities.bazarr: false, and SERVER.md marks SV-C3 missing.

The fix

  • POST /v1/asr and POST /v1/detect-language (new src/main/api/routes/bazarr.ts). Bazarr's endpoint is http://host:8476/v1. Both routes are open, and they answer only while server.bazarr is on (AKOU_BAZARR, file or env only, apiWritable: false). Off, both answer 404 not_found with "server.bazarr is off". A key sent as Authorization: Bearer is honoured and the job runs under it. With no key the job runs as the stand-in identity bazarr.
  • encode=false: the spool gets a 44-byte WAV header and is copied once, hashed on the way, so the decoder reads it without ffmpeg. encode=true passes the container to ffmpeg as sent.
  • /asr runs the server default (chooseModel(jobs, {}, …, true)), in language or server.default_language, as a quiet job with the OpenAI door's wait loop. A caller that hangs up cancels the job, and the job is deleted once the answer is sent. output=srt|vtt|txt comes from renderResult, so cues hold at most 42 characters and keep the audio's own times. task=translate is 400 bad_param.
  • /detect-language transcribes only the first 30 s (960 000 PCM bytes) of raw PCM under best. With encode=true, which Bazarr never sends, the whole file is decoded; the route doc and docs/server.md say so. It answers {detected_language, language_code, confidence: null}, or unknown/und when no language was heard. With best refused, akou's own 409 JSON passes through.
  • Bazarr reads only the body, so every refusal is also one bazarr: warn line in the server log, with the status and code.
  • capabilities.bazarr is has("POST", "/asr") && server.bazarr === true. The header comment of routes/server.ts gains the clause for dialects a setting turns on.
  • COMPAT_TAGS = ["openai", "bazarr"] in openapi.ts, so both routes carry x-akou-door: compat and stay out of the ?scope=jobs view.
  • Settings: server.bazarr after server.behind_proxy, a "Bazarr" group after "Other servers", and its label before server.dictation_slots.
  • Contracts: the route-access rows, the parity row, serverJobGaps, and the regenerated docs/configuration.md, docs/api/openapi.json and docs/cli.md.
  • Docs: SERVER.md row SV-C3 says has, line 13 says all three dialects are built, and README.md:29, docs/index.md:90 and docs/server.md:3 are flipped back from "planned". docs/server.md gets a Home Assistant and a Bazarr section (endpoint, Host rule, no key, timeout, translate, best, Test Connection, a curl check).

The Wyoming lane (#395) merged first, and main is merged into this branch (a merge commit, no rebase), so the shared sentences that call Wyoming built are true.

The one experiment (design section 6)

A job with language=jw (and haw, no) through the fake llama rig, on best and on fast: every job came back done with "hello world". Qwen does not know jw, so it falls back to auto and names en; Parakeet keeps the hint. No 500, so there is no jw→jv mapping.

Tests

tests/bazarr.e2e.test.ts, 12 tests, all [SV-C3]:

  • Bazarr's exact /asr request: a hand-built multipart body (a part with a filename and no Content-Type), User-Agent: Subliminal/2.1, no Authorization, encode=false raw s16le of 3 s silence plus "hello world". It gets 200 text/plain and an SRT whose first cue starts at or after 00:00:02,500. The job ran as bazarr, and no upload is left.
  • encode=true with a WAV; vtt and txt; translate, other enum values, a bad language tag and an extra part; a Bearer key honoured, an unknown bearer treated as anonymous; capabilities true; PATCH /v1/config refuses the key.
  • Off: both routes 404 not_found, capabilities false.
  • /detect-language on the fake llama with --fake-lang Spanish answers spanish/es/null on a 40 s track, and the decoder saw exactly 480 000 samples.
  • best refused (auto_download off, no Qwen): 409 preset_unavailable, no language_code, a warn line.
  • A full queue: 429 queue_full JSON, and the refused body is never kept.

The contract tests changed with it: tests/openapi.test.ts (new control: a bazarr-tagged operation without the door is reported), tests/scopes.test.ts, tests/server-mode.e2e.test.ts (capabilities.bazarr false by default), tests/api.e2e.test.ts (file-only keys), tests/server-image.test.ts.

CI: a new step in the server job, Bazarr-shaped /asr against the image (SV-C3). It starts the image with AKOU_BAZARR=true, checks capabilities.bazarr, decodes en.wav to s16le with the image's ffmpeg, sends Bazarr's request with curl, and checks the SRT.

Red controls, each watched failing

Each mutation was applied to a scratch copy, the test file was run, and the mutation was reverted.

  • SRT rendered as text: Expected substring or pattern: /^1\r?\n(\d\d:\d\d:\d\d,\d{3}) --> \d\d:\d\d:\d\d,\d{3}\r?\nhello world/ / Received: "hello world\n".
  • Absolute times (the copy skips the first 3 s of PCM): expect(received).toBeGreaterThanOrEqual(expected) / Expected: >= 0 / Received: -1 on the first cue's start against 00:00:02,500.
  • capabilities.bazarr ignoring the setting: Expected: false / Received: true in the off test.
  • The 404 gate removed from /asr: Expected: "/asr?output=srt&encode=false 404" / Received: "/asr?output=srt&encode=false 200".
  • /detect-language not capped at 30 s: Expected: 480000 / Received: 642240.
  • The bearer ignored: Expected to end with: " key key_ecdc16a4" / Received: "job.created job_… key bazarr".
  • COMPAT_TAGS without bazarr: + "POST /v1/asr: x-akou-door: compat on tag bazarr, not one of openai" in the committed-file check.
  • In the test file itself: the SRT parser throws is not SRT on a JSON refusal, and the same bytes as a text part (no filename) get 413 or 422, so the main test really sends a file part.
  • The CI step's SRT check, run on a box: it passes on the real SRT and on a phrase split across two cues, and fails on a JSON refusal body.

On real models (a Mac mini M4, akou serve from this branch, Parakeet and Qwen on disk)

The exact curl of the CI step, on en.wav decoded to s16le:

1
00:00:00,064 --> 00:00:02,064
Ask not what your country can do for you,

2
00:00:02,064 --> 00:00:03,664
ask what you can do for your country.

With best as the default, Qwen gives no word times; before the cue fix below this gave one whole-segment cue, now the segment is cut into cues of at most 42 characters. task=translate gives 400 bad_param and the log line akou warn: bazarr: POST /v1/asr 400 bad_param: task=translate is not supported: akou transcribes in the language spoken. /detect-language gives {"detected_language":"english","language_code":"en","confidence":null}. Every job logs key bazarr.

Merged main after Wyoming (#395)

git merge origin/main (c8f18df). Two textual conflicts, resolved with the design's final text:

  • src/main/api/routes/server.ts capabilities: Wyoming's wyoming: (c.app.wyomingPort?.() ?? null) !== null and this branch's bazarr: line, each with its comment. The header clause for dialects a setting turns on stays.
  • docs/ux/SERVER.md: Wyoming's SV-C2 row and this branch's SV-C3 row.

Schema keys, settings labels and groups, the capability assertions in tests/server-mode.e2e.test.ts, both serverJobGaps lists, the file-only keys in tests/api.e2e.test.ts, ci.yml and the other SERVER.md rows merged cleanly at their separate anchors. docs/configuration.md and docs/cli.md regenerate byte-identical after the merge; docs/api/openapi.json changed only by the detect-language doc line below.

Cue fix: a segment with no word times is cut into 42-character cues

The 42-character rule (SV-J5) applied only when every word had times. Under Qwen no word does, so renderResult fell back to whole segments and a Bazarr SRT cue could run far past 42 characters. The fix is in the shared renderResult, so the OpenAI door and GET /v1/jobs/{id}/result get it too: segmentCues cuts a long segment at word boundaries into cues of at most CUE_CHARS, and shares the segment's time across them by character count, so the cues partition the segment. No existing test pinned the old fallback; the wordCues unit test still expects null for untimed words, which is unchanged.

Test [SV-J5] a segment with no timed words (Qwen) is cut into cues of at most 42 characters that partition its time in tests/openai.e2e.test.ts: one 120-character segment from 10 s to 22 s with untimed words, rendered as SRT. Every cue is at most 42 characters, the first starts at 00:00:10,000, each starts where the last ended, the last ends at 00:00:22,000, and the joined text is the segment's. Red on the previous head e1ec120 with the renderer unchanged:

427 |     expect(cues.length).toBeGreaterThan(1);
error: expect(received).toBeGreaterThan(expected)

Expected: > 1
Received: 1

Doc lines

  • docs/server.md, Home Assistant: with server.auto_download on (the default), the first utterance after turning on a preset that is not downloaded waits for the download, and Home Assistant may hit its 300 s pipeline timeout once. After a new preset is installed the Wyoming entry needs a reload, because it reads the language list at setup.
  • docs/server.md, Bazarr, and the /detect-language route doc: with encode=true the whole file is decoded.
  • SERVER.md SV-J5 row: the cue rule now covers segments without word times.

Deviations from the design

  • CI step placement. The design puts the step after the SV-T6 step and reads capabilities.bazarr from server.json. But the SV-T6 step runs docker rm -f akou, and compose-e2e.sh tears its stack down on exit, so nothing listens on 8476 after it. The step starts its own container with -e AKOU_BEHIND_PROXY=true -e AKOU_BAZARR=true and reads /v1/server from it. It no longer depends on the Wyoming lane adding AKOU_BAZARR to the main docker run line, and this branch does not touch that line.
  • CI phrase check. The design greps the SRT line by line. Cues hold 42 characters at most, so "ask not what your country" can span two cues. The step joins the cue text first (tr -s ' \n' ' '). The design's line-by-line grep fails on a split cue; the join passes it and still fails on a refusal body.
  • A log seam. The design asks for warn lines, but routes have no logger and index.ts is not this lane's. JobService gains a public log(level, msg) that forwards to its existing o.log (src/main/server/jobs.ts, 4 lines).
  • tests/scopes.test.ts. The SV-T5 walk runs an app-mode server, where a server-only route is an unknown path (UNKNOWN_ROUTE: any key). It expected open rows to pass with no key, so the first server-only open routes failed it. The walk now treats a server-only row as jobs there, and the positive control counts only the open rows the app serves. The design said no access test needed an edit; it missed this one.
  • tests/api.e2e.test.ts lists every file-only key; server.bazarr joins it beside the Wyoming lane's two keys.

Bazarr itself was not run; CI and the box above send the request its source builds.

Refs akou-5an.39

…les from akou with no key

Bazarr's whisperai provider sends POST {endpoint}/asr with raw 16 kHz mono
s16le PCM in one `audio_file` part and no key, and POST
{endpoint}/detect-language with the whole track. akou now answers both under
/v1 while `server.bazarr` (AKOU_BAZARR, file or env only) is on, and 404 while
it is off. Raw PCM gets a 44-byte WAV header so the decoder reads it without
ffmpeg; the answer is an SRT, WebVTT or text from the job's result, with
42-character cues at the audio's own times. Detection transcribes the first
30 s under `best` and answers whisper-asr-webservice's JSON shape.

Refs akou-5an.39
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: GeiserX/akou/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05129624-3249-4aa8-9d4e-44abea0f0c41

📥 Commits

Reviewing files that changed from the base of the PR and between c8f18df and b20adbe.


📒 Files selected for processing (27)
  • .github/workflows/ci.yml
  • README.md
  • docs/api/openapi.json
  • docs/cli.md
  • docs/configuration.md
  • docs/index.md
  • docs/server.md
  • docs/ux/SERVER.md
  • src/main/api/openapi.ts
  • src/main/api/routes/bazarr.ts
  • src/main/api/routes/jobs.ts
  • src/main/api/routes/openai.ts
  • src/main/api/routes/server.ts
  • src/main/api/server.ts
  • src/main/config/schema.ts
  • src/main/server/jobs.ts
  • src/ui/settings-labels.ts
  • src/ui/settings-page.ts
  • tests/api.e2e.test.ts
  • tests/bazarr.e2e.test.ts
  • tests/contracts/parity.ts
  • tests/fixtures/route-access.ts
  • tests/openai.e2e.test.ts
  • tests/openapi.test.ts
  • tests/scopes.test.ts
  • tests/server-image.test.ts
  • tests/server-mode.e2e.test.ts

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

# Conflicts:
#	docs/ux/SERVER.md
#	src/main/api/routes/server.ts
…itle never runs past a line

Under Qwen no word has a time, so renderResult fell back to whole segments
and an SRT cue for Bazarr or GET /v1/jobs/{id}/result could run far past
CUE_CHARS. segmentCues cuts such a segment at word boundaries and shares its
time across the cues by character count, so the cues partition the segment.
…true, and what Home Assistant waits for

The 30 s cap applies to Bazarr's raw PCM only. Home Assistant waits for a
first preset download and reads the language list at setup, so a new
preset needs an entry reload.
@GeiserX
GeiserX merged commit b87ba3b into main Oct 11, 2026
34 checks passed
@GeiserX
GeiserX deleted the feat/server-bazarr branch October 11, 2026 22:34
GeiserX added a commit that referenced this pull request Oct 12, 2026
… window behaves (#400)

The version bump for 1.1.0. The release itself is the `v1.1.0` tag on main once this is merged and `ci-ok` is green there.

## What 1.1.0 ships

The CHANGELOG section in this PR is the release note. In short: the server speaks Wyoming for Home Assistant's Assist (#395) and answers Bazarr's whisper endpoints (#396), both off by default; the desktop window stops scrolling past the app and the note and fix boxes grow with their text (#397); the ask box pre-starts the harness (#393); the recognizer loads from the call's start (#394); on four x64 cores a live line commits 0.4 s sooner (#391); the Docker Hub page is filled from the README (#389, #390); the watchdog test and the nightly stop flaking (#392, #399).

## The evidence a stable release needs (CI-28)

- **The 8-hour soak**, at real time with a busy process on every core, through the Rust helper in file mode, on main at b87ba3b (every change in this release but the UI-only #397): 9 of 9 checks ok, no audio hole, heap growth 0.16 MB, event loop late by at most 186 ms. The JSON is `docs/gates/soak-1.1.0.json`.
- **The terms table** has a row dated 2026-10-12. Both vendors' pages were read again today. Anthropic's pages are unchanged word for word. OpenAI's pages refuse plain fetches and the web archive was offline, so they were read in a browser: same dates, same clauses. The Consumer Terms outside the EEA could not be re-read today, and the row says so.
- `bun scripts/stamp-version.ts --check --tag v1.1.0` exits 0; with `v1.1.1` it exits 1, the control.

## Also in this PR

- The server docs' image tags and the README's DMG name say 1.1.0.
- `docs/DESIGN.md` step 6 states the x64 provisional rule that #391 introduced, which the judge of that PR asked for.

Depends on #399 merging first, since the CHANGELOG names it; I will bring main into this branch once it lands.
GeiserX added a commit that referenced this pull request Oct 13, 2026
…preset (#405)

Bazarr now sends whole films to the server (#396). A model that hears room noise or music and no speech can write a sentence anyway ("thank you for watching", the way Qwen3-ASR did before sherpa-onnx 1.13.8), or loop on one word. On a film that becomes a wrong subtitle. SV-R5 was partial: the job pass already trimmed noise with the VAD, but the recognizer loaded before the VAD ran, the result had no way to say "no speech", nothing caught a decoder loop, and only `fast` and `auto` were tested.

The fix:

- **VAD before any model.** Every job runs the VAD before anything loads. A file with no speech ends `done` with `text: ""`, `segments: []` and a new `note: "no_speech"`, and loads no recognizer and no engine. Leading and trailing noise is still trimmed, with segment times in the file's clock, and a piece the VAD heard no speech in is still never decoded.
- **Loop guard.** A decoded piece that loops on a short phrase keeps the phrase once and the words after it, in its text and its words alike. The bar is eight repeats in a row for a one- or two-word phrase and five for three or four words, so film lines such as "No, no, no, no, no!" or "Go! Go! Go!" stay whole. Han and kana text is matched by character with punctuation passed over, so a loop of 谢谢观看。 is cut to one, and a whitespace-split Qwen word holding it is cut to the same characters.
- **Logs.** Each undecoded piece and each cut is one `debug` line with times and counts, never the dropped text. Debug lines go to `app.log` only.
- **Bazarr.** `/asr` on noise answers 200 with an empty subtitle. `/detect-language` with no speech in the first 30 s answers 200 `unknown` / `und`.

Tests, all named `[T4.37]` (new TRAPS row "Invented sentence on silence"):

- `tests/silence-guards.test.ts` covers room noise through each preset's pass shape (recognizer, one engine, fusion list) with engines that invent on every unit: empty text, `no_speech`, nothing loaded or asked. A positive control shows that -30 dBFS pink noise does reach the engines and come back invented when the VAD is only an energy gate. Where the Silero model is on disk, the real VAD runs on -30 dBFS white and pink noise, and on the first sentence of the generated `two-voices.wav` fixture in noise. The speech keeps its text and its times in the file's clock. The loop-guard cases are in the same file.
- Through the API: `fast` and `auto` in `jobs.e2e`, `best` (the fake Qwen gets no request), `fusion` (no engine runs), and both Bazarr routes.
- The `server-macos` CI job already pulls the real `fast` models. It now runs `silence-guards.test.ts` and fails if a test skips there. The check jobs skip those two tests, so `maxSkip` goes up by 2.
- Mutation checks run locally: with the loop guard disabled, 4 loop tests fail. With a bar of 5 for short phrases, the film-line tests fail. Without the word alignment, the Han words test fails. Without the energy gate, the digital-silence test fails, because its VAD hears speech everywhere. With the recognizer loaded before the VAD again, the recognizer-shape noise test and the real-VAD noise test fail. With the trim disabled, the speech-in-noise test fails.
- Two halving fixtures said "world hello" 35 times, which is a loop by the guard's own rule. They now cycle five words.

Not verified: how a real Bazarr instance handles an empty SRT body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant