speaker_helper.api module
REST API server for speaker-helper.
Module summary
A thin FastAPI façade over Speaker, suitable
for running as a Docker service. It exposes:
GET /health— liveness plus the upstream engine health.GET /voices— preset voices for the configured (or requested) engine.POST /synth— synthesise{"text": ..., "language": ...}and return aaudio/wavbody (offline: whole text in one response).POST /synth/stream— same body, but stream Server-Sent Events, one per sentence-sized chunk, as soon as each is ready (low time-to-first-audio). Each event’sdatais JSON withseq,duration_s,rtf,ttfa_s(first chunk only),is_final, and base64audio(WAV).POST /clone— multipart upload of reference audio (plus optional transcripts) to clone a voice; missing transcripts come fromvocal-helper. The clone becomes the server’s active voice for subsequent/synthcalls.
When fastapi-mcp is installed, a Model Context Protocol server is also
mounted at /mcp, exposing these endpoints as MCP tools so an assistant can
synthesise, stream, clone, and list voices directly.
This module imports FastAPI/pydantic/uvicorn at import time, so it is only ever
imported behind the server extra (the CLI imports it lazily, and the core
package never imports it). Keeping the request model at module scope lets
FastAPI correctly resolve it as a request body rather than query params.
Usage example
speaker-helper serve --host 0.0.0.0 --port 8080
curl -s -X POST localhost:8080/synth -H 'content-type: application/json' \
-d '{"text": "Bonjour."}' -o out.wav
- class speaker_helper.api.RouteRequestBody(*, condition, language='fr', rtf_ceiling=0.8, rtf_budget=None, quality_floor=None)[source]
Bases:
BaseModelRequest body for
POST /route.- Parameters:
condition (str) –
"online_realtime"(delay-bounded streaming) or"offline"(quality-only batch).language (str) – ISO-639-1 target language driving the candidate catalogue.
rtf_ceiling (float) – Online only: the
mean_rtfan engine must beat to keep up (default0.8).rtf_budget (float or None) – Offline only: optional patience cap on
mean_rtf.quality_floor (float or None) – Reject candidates below this quality in either condition.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class speaker_helper.api.SynthRequest(*, text, language=None)[source]
Bases:
BaseModelRequest body for
POST /synth.- Parameters:
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- speaker_helper.api.create_app(settings=None, *, enable_mcp=True)[source]
Build the FastAPI application.
- Parameters:
settings (Settings or None) – Configuration; defaults to
Settings.load().enable_mcp (bool) – When
True(default) andfastapi-mcpis installed, mount a Model Context Protocol server at/mcpthat exposes the REST endpoints as MCP tools — so an MCP client (an assistant) can synthesise, clone, and list voices directly. Silently skipped iffastapi-mcpis absent.
- Returns:
The configured application. A single shared
Speakeris created at startup and closed at shutdown.- Return type:
fastapi.FastAPI