Define the TTS engine adapter contract and registry #8

Closed
opened 2026-10-25 14:58:13 +00:00 by dsh · 1 comment
Owner

Goal

One small interface every engine implements, so the queue, settings and capture code never learn engine specifics.

Scope

  • Document and implement TtsEngine (JSDoc): id, label, kind: 'local' | 'cloud', init(settings), listVoices(), prepare(voiceId, onProgress) (local only), synthesize(text, { voice, rate, signal }), dispose().
  • synthesize resolves { audio: AudioBuffer } or { pcm: Float32Array, sampleRate }; throw typed errors (EngineUnavailable, DownloadRequired, SynthesisFailed, Cancelled).
  • Registry: register/get/list, id uniqueness enforced, active() resolution from settings with a sane fallback when the configured engine is unavailable.
  • Adapters never touch DOM or localStorage; settings are passed in. AbortSignal honoured at every async boundary.
  • Unit tests with a fake adapter: registry lifecycle, fallback, abort, error types.
  • Add the contract + a skeleton adapter to docs/dev-plan.md/AGENTS.md so a new engine has a checklist.

Acceptance

  • A new adapter can be added without editing the queue, capture, or settings code.
  • An unavailable engine degrades to a clear, non-fatal state (settings shows why) instead of silence.

Notes

## Goal One small interface every engine implements, so the queue, settings and capture code never learn engine specifics. ## Scope - [ ] Document and implement `TtsEngine` (JSDoc): `id`, `label`, `kind: 'local' | 'cloud'`, `init(settings)`, `listVoices()`, `prepare(voiceId, onProgress)` (local only), `synthesize(text, { voice, rate, signal })`, `dispose()`. - [ ] `synthesize` resolves `{ audio: AudioBuffer }` or `{ pcm: Float32Array, sampleRate }`; throw typed errors (`EngineUnavailable`, `DownloadRequired`, `SynthesisFailed`, `Cancelled`). - [ ] Registry: register/get/list, id uniqueness enforced, `active()` resolution from settings with a sane fallback when the configured engine is unavailable. - [ ] Adapters never touch DOM or `localStorage`; settings are passed in. AbortSignal honoured at every async boundary. - [ ] Unit tests with a fake adapter: registry lifecycle, fallback, abort, error types. - [ ] Add the contract + a skeleton adapter to `docs/dev-plan.md`/AGENTS.md so a new engine has a checklist. ## Acceptance - A new adapter can be added without editing the queue, capture, or settings code. - An unavailable engine degrades to a clear, non-fatal state (settings shows why) instead of silence. ## Notes - Depends on #1. Blocks #9, #10, #14, #16. Part of M1.
Author
Owner

Done in d5c638e. src/engines/contract.js: TtsError + four typed subclasses with stable codes, assertEngine, createEngineRegistry (register/get/list/has/resolve/disposeAll, duplicate ids rejected, stale-safe disposers, AggregateError on dispose failures); 29 tests. Contract JSDoc + a copy-ready skeleton added to docs/dev-plan.md §7.1. CI run #2 green.

**Done** in `d5c638e`. `src/engines/contract.js`: `TtsError` + four typed subclasses with stable codes, `assertEngine`, `createEngineRegistry` (register/get/list/has/resolve/disposeAll, duplicate ids rejected, stale-safe disposers, AggregateError on dispose failures); 29 tests. Contract JSDoc + a copy-ready skeleton added to `docs/dev-plan.md` §7.1. CI run #2 green.
dsh closed this issue 2026-10-25 17:43:52 +00:00
Sign in to join this conversation.
No description provided.