How ekwek1/soprano works
Purpose and entry points
Soprano is a local, English text-to-speech inference package that generates 32 kHz audio, including batched and low-latency streaming modes. Its core Python API is SopranoTTS in soprano/tts.py, re-exported through soprano/__init__.py. Operational entry points are the command-line interface (soprano/cli.py), OpenAI-compatible ASGI server (soprano/server.py), and local browser UI (soprano/webui.py).
TTS orchestration
SopranoTTS owns model/backend initialization and exposes non-streaming, batch, and streaming inference. It is the main boundary between user-facing inputs—text, output paths, sampling parameters, cache and decoder settings—and backend/model execution.
Paths: soprano/tts.py, soprano/__init__.py.
Backend abstraction and runtime selection
A common backend contract isolates generation engines from TTS orchestration. The Transformers backend supports broad CPU/CUDA/MPS execution, while LMDeploy is the optional optimized CUDA-oriented engine. Automatic selection resolves auto backend/device choices, allowing callers to retain one API while deployment characteristics determine execution.
Paths: soprano/backends/base.py, soprano/backends/transformers.py, soprano/backends/lmdeploy.py, soprano/utils/auto_select.py.
Text preparation and long-input control
Input text is normalized and split before generation. This establishes the infinite-length behavior: long requests are partitioned into suitable synthesis segments rather than requiring a bounded model context. The output path must preserve ordering and concatenate or stream segment audio without audible loss.
Paths: soprano/utils/text_normalizer.py, soprano/utils/text_splitter.py, soprano/tts.py.
Generation-to-audio decoding
The selected language-model backend produces acoustic/token representations, which are converted into waveform audio through the embedded Vocos decoder implementation. Vocos is an internal model subsystem rather than an external service, containing decoder, heads, learned model definitions, neural modules, and spectral operations.
Paths: soprano/vocos/decoder.py, soprano/vocos/models.py, soprano/vocos/spectral_ops.py.
Streaming boundary
Streaming inference emits audio incrementally from SopranoTTS, enabling playback before the full text completes. Streaming utilities consume these chunks for local speaker playback; the notebook demonstrates this integration. The HTTP endpoint is explicitly non-streaming, so stream handling remains a Python/CLI/UI-side capability rather than an API transport guarantee.
Paths: soprano/tts.py, soprano/utils/streaming.py, examples/streaming.ipynb.
Serving and user interfaces
The CLI is suitable for one-shot synthesis and optional speaker streaming, but reloads models per invocation. The server exposes an OpenAI-compatible /v1/audio/speech endpoint via Uvicorn/ASGI. The WebUI provides a persistent interactive process and surfaces performance controls such as LMDeploy cache size and decoder batch size.
Paths: soprano/cli.py, soprano/server.py, soprano/webui.py.
Dependencies and external model boundary
Inference depends on PyTorch-compatible devices (CPU, CUDA, MPS); LMDeploy is an optional backend extra. Model weights are supplied by a local model path or obtained from the published Hugging Face model distribution, making weight acquisition/loading the principal external artifact boundary. The package does not require a hosted inference service for normal operation.
Paths: pyproject.toml, soprano/tts.py, soprano/backends/transformers.py.
Main entry points: tts.py SopranoTTS · base.py Backend contract · decoder.py Vocos decoder · text_normalizer.py Text normalizer
Components 18
User Interfaces
- Python API
soprano/__init__.py - CLI · One-shot synthesis with optional speaker streaming.
soprano/cli.py - OpenAI ASGI server · Provides non-streaming /v1/audio/speech.
soprano/server.py - Local WebUI · Persistent UI exposes runtime performance controls.
soprano/webui.py - Streaming notebook
examples/streaming.ipynb
Synthesis Pipeline
- SopranoTTS · Owns model initialization and batch, standard, and streaming inference.
soprano/tts.py - Text normalizer
soprano/utils/text_normalizer.py - Text splitter · Partitions long input into ordered synthesis segments.
soprano/utils/text_splitter.py - Streaming playback · Consumes incremental audio chunks for local playback.
soprano/utils/streaming.py
Generation Runtimes
- Backend contract
soprano/backends/base.py - Runtime selection · Resolves auto backend and device choices.
soprano/utils/auto_select.py - Transformers backend · Broad CPU, CUDA, and MPS execution.
soprano/backends/transformers.py - LMDeploy backend · Optimized CUDA-oriented engine.
soprano/backends/lmdeploy.py
Audio Decoder
- Vocos decoder
soprano/vocos/decoder.py - Vocos model definitions
soprano/vocos/models.py - Spectral operations
soprano/vocos/spectral_ops.py
Other components
- Model weights · Loaded locally or acquired from the published Hugging Face distribution.
- 32 kHz audio · Returned, saved, concatenated, or emitted as chunks.
Connections 20
- Python API → SopranoTTS: exports
- CLI → SopranoTTS: synthesis requests
- OpenAI ASGI server → SopranoTTS: speech requests
- Local WebUI → SopranoTTS: interactive requests
- Streaming notebook → SopranoTTS: streaming inference
- SopranoTTS → Text normalizer: normalizes text
- Text normalizer → Text splitter: prepared text
- Text splitter → Backend contract: ordered segments
- SopranoTTS → Runtime selection: selects runtime
- Runtime selection → Backend contract: binds backend/device
- Transformers backend → Backend contract: implements
- LMDeploy backend → Backend contract: implements
- Model weights → SopranoTTS: loaded during initialization
- Backend contract → Vocos decoder: acoustic tokens
- Vocos model definitions → Vocos decoder: decoder architecture
- Spectral operations → Vocos decoder: spectral processing
- Vocos decoder → 32 kHz audio: 32 kHz waveform
- SopranoTTS → Streaming playback: incremental chunks
- Streaming playback → 32 kHz audio: plays chunks
- SopranoTTS → 32 kHz audio: concatenates segments