# ekwek1/soprano architecture

> Architecture diagram of the GitHub repository ekwek1/soprano, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ekwek1/soprano
- Repository: https://github.com/ekwek1/soprano

## Overview

#### 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: [`soprano/tts.py`](https://github.com/ekwek1/soprano/blob/main/soprano/tts.py) (SopranoTTS), [`soprano/backends/base.py`](https://github.com/ekwek1/soprano/blob/main/soprano/backends/base.py) (Backend contract), [`soprano/vocos/decoder.py`](https://github.com/ekwek1/soprano/blob/main/soprano/vocos/decoder.py) (Vocos decoder), [`soprano/utils/text_normalizer.py`](https://github.com/ekwek1/soprano/blob/main/soprano/utils/text_normalizer.py) (Text normalizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_python_api["Python API<br/>package export<br/>[__init__.py]"]
  node_cli["CLI<br/>command interface<br/>[cli.py]"]
  node_server["OpenAI ASGI server<br/>HTTP service<br/>[server.py]"]
  node_webui["Local WebUI<br/>interactive UI<br/>[webui.py]"]
  node_streaming_example["Streaming notebook<br/>example client<br/>[streaming.ipynb]"]
end

subgraph group_core["Synthesis Pipeline"]
  node_tts{{"SopranoTTS<br/>orchestrator<br/>[tts.py]"}}
  node_normalizer["Text normalizer<br/>text preparation<br/>[text_normalizer.py]"]
  node_splitter["Text splitter<br/>long-input control<br/>[text_splitter.py]"]
  node_streaming_utils["Streaming playback<br/>chunk consumer<br/>[streaming.py]"]
end

subgraph group_runtimes["Generation Runtimes"]
  node_backend_contract["Backend contract<br/>generation interface<br/>[base.py]"]
  node_auto_select["Runtime selection<br/>selection policy<br/>[auto_select.py]"]
  node_transformers["Transformers backend<br/>generation runtime<br/>[transformers.py]"]
  node_lmdeploy["LMDeploy backend<br/>optional generation runtime<br/>[lmdeploy.py]"]
end

subgraph group_audio["Audio Decoder"]
  node_vocos_decoder{{"Vocos decoder<br/>token-to-waveform decoder<br/>[decoder.py]"}}
  node_vocos_models["Vocos model definitions<br/>neural modules<br/>[models.py]"]
  node_spectral_ops["Spectral operations<br/>audio operations<br/>[spectral_ops.py]"]
end

node_weights[("Model weights<br/>external artifact")]
node_audio_output["32 kHz audio<br/>waveform output"]

node_python_api -->|"exports"| node_tts
node_cli -->|"synthesis requests"| node_tts
node_server -->|"speech requests"| node_tts
node_webui -->|"interactive requests"| node_tts
node_streaming_example -->|"streaming inference"| node_tts
node_tts -->|"normalizes text"| node_normalizer
node_normalizer -->|"prepared text"| node_splitter
node_splitter -->|"ordered segments"| node_backend_contract
node_tts -->|"selects runtime"| node_auto_select
node_auto_select -->|"binds backend/device"| node_backend_contract
node_transformers -.->|"implements"| node_backend_contract
node_lmdeploy -.->|"implements"| node_backend_contract
node_weights -->|"loaded during initialization"| node_tts
node_backend_contract -->|"acoustic tokens"| node_vocos_decoder
node_vocos_models -->|"decoder architecture"| node_vocos_decoder
node_spectral_ops -->|"spectral processing"| node_vocos_decoder
node_vocos_decoder -->|"32 kHz waveform"| node_audio_output
node_tts -->|"incremental chunks"| node_streaming_utils
node_streaming_utils -->|"plays chunks"| node_audio_output
node_tts -->|"concatenates segments"| node_audio_output

click node_python_api "https://github.com/ekwek1/soprano/blob/main/soprano/__init__.py"
click node_cli "https://github.com/ekwek1/soprano/blob/main/soprano/cli.py"
click node_server "https://github.com/ekwek1/soprano/blob/main/soprano/server.py"
click node_webui "https://github.com/ekwek1/soprano/blob/main/soprano/webui.py"
click node_streaming_example "https://github.com/ekwek1/soprano/blob/main/examples/streaming.ipynb"
click node_tts "https://github.com/ekwek1/soprano/blob/main/soprano/tts.py"
click node_normalizer "https://github.com/ekwek1/soprano/blob/main/soprano/utils/text_normalizer.py"
click node_splitter "https://github.com/ekwek1/soprano/blob/main/soprano/utils/text_splitter.py"
click node_streaming_utils "https://github.com/ekwek1/soprano/blob/main/soprano/utils/streaming.py"
click node_backend_contract "https://github.com/ekwek1/soprano/blob/main/soprano/backends/base.py"
click node_auto_select "https://github.com/ekwek1/soprano/blob/main/soprano/utils/auto_select.py"
click node_transformers "https://github.com/ekwek1/soprano/blob/main/soprano/backends/transformers.py"
click node_lmdeploy "https://github.com/ekwek1/soprano/blob/main/soprano/backends/lmdeploy.py"
click node_vocos_decoder "https://github.com/ekwek1/soprano/blob/main/soprano/vocos/decoder.py"
click node_vocos_models "https://github.com/ekwek1/soprano/blob/main/soprano/vocos/models.py"
click node_spectral_ops "https://github.com/ekwek1/soprano/blob/main/soprano/vocos/spectral_ops.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_python_api,node_cli,node_server,node_webui,node_streaming_example toneBlue
class node_tts,node_normalizer,node_splitter,node_streaming_utils toneAmber
class node_backend_contract,node_auto_select,node_transformers,node_lmdeploy toneMint
class node_vocos_decoder,node_vocos_models,node_spectral_ops toneRose
class node_weights,node_audio_output toneNeutral
```

## Components

### User Interfaces

- [Python API](https://github.com/ekwek1/soprano/blob/main/soprano/__init__.py): package export · `soprano/__init__.py`
- [CLI](https://github.com/ekwek1/soprano/blob/main/soprano/cli.py): command interface · One-shot synthesis with optional speaker streaming. · `soprano/cli.py`
- [OpenAI ASGI server](https://github.com/ekwek1/soprano/blob/main/soprano/server.py): HTTP service · Provides non-streaming /v1/audio/speech. · `soprano/server.py`
- [Local WebUI](https://github.com/ekwek1/soprano/blob/main/soprano/webui.py): interactive UI · Persistent UI exposes runtime performance controls. · `soprano/webui.py`
- [Streaming notebook](https://github.com/ekwek1/soprano/blob/main/examples/streaming.ipynb): example client · `examples/streaming.ipynb`

### Synthesis Pipeline

- [SopranoTTS](https://github.com/ekwek1/soprano/blob/main/soprano/tts.py): orchestrator · Owns model initialization and batch, standard, and streaming inference. · `soprano/tts.py`
- [Text normalizer](https://github.com/ekwek1/soprano/blob/main/soprano/utils/text_normalizer.py): text preparation · `soprano/utils/text_normalizer.py`
- [Text splitter](https://github.com/ekwek1/soprano/blob/main/soprano/utils/text_splitter.py): long-input control · Partitions long input into ordered synthesis segments. · `soprano/utils/text_splitter.py`
- [Streaming playback](https://github.com/ekwek1/soprano/blob/main/soprano/utils/streaming.py): chunk consumer · Consumes incremental audio chunks for local playback. · `soprano/utils/streaming.py`

### Generation Runtimes

- [Backend contract](https://github.com/ekwek1/soprano/blob/main/soprano/backends/base.py): generation interface · `soprano/backends/base.py`
- [Runtime selection](https://github.com/ekwek1/soprano/blob/main/soprano/utils/auto_select.py): selection policy · Resolves auto backend and device choices. · `soprano/utils/auto_select.py`
- [Transformers backend](https://github.com/ekwek1/soprano/blob/main/soprano/backends/transformers.py): generation runtime · Broad CPU, CUDA, and MPS execution. · `soprano/backends/transformers.py`
- [LMDeploy backend](https://github.com/ekwek1/soprano/blob/main/soprano/backends/lmdeploy.py): optional generation runtime · Optimized CUDA-oriented engine. · `soprano/backends/lmdeploy.py`

### Audio Decoder

- [Vocos decoder](https://github.com/ekwek1/soprano/blob/main/soprano/vocos/decoder.py): token-to-waveform decoder · `soprano/vocos/decoder.py`
- [Vocos model definitions](https://github.com/ekwek1/soprano/blob/main/soprano/vocos/models.py): neural modules · `soprano/vocos/models.py`
- [Spectral operations](https://github.com/ekwek1/soprano/blob/main/soprano/vocos/spectral_ops.py): audio operations · `soprano/vocos/spectral_ops.py`

### Other components

- **Model weights**: external artifact · Loaded locally or acquired from the published Hugging Face distribution.
- **32 kHz audio**: waveform output · Returned, saved, concatenated, or emitted as chunks.

## Connections

- 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
