supertonic.pipeline¶
supertonic.pipeline ¶
High-level TTS interface for Supertonic.
This module provides the main TTS class for easy text-to-speech synthesis with automatic model loading and voice style management.
Classes:
| Name | Description |
|---|---|
TTS | High-level interface for Supertonic text-to-speech synthesis. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger | |
TTS ¶
TTS(
model_dir: Optional[Union[Path, str]] = None,
auto_download: bool = True,
intra_op_num_threads: Optional[int] = None,
inter_op_num_threads: Optional[int] = None,
)
High-level interface for Supertonic text-to-speech synthesis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Optional[Union[Path, str]] | Directory containing model files. If None, uses default cache directory (~/.cache/supertonic) | None |
auto_download | bool | If True, automatically downloads model files from HuggingFace Hub if they're missing | True |
intra_op_num_threads | Optional[int] | Number of threads for intra-op parallelism. If None (default), ONNX Runtime automatically determines optimal value based on your system. Can also be set via SUPERTONIC_INTRA_OP_THREADS environment variable | None |
inter_op_num_threads | Optional[int] | Number of threads for inter-op parallelism. If None (default), ONNX Runtime automatically determines optimal value based on your system. Can also be set via SUPERTONIC_INTER_OP_THREADS environment variable | None |
Attributes:
| Name | Type | Description |
|---|---|---|
model | Supertonic | The underlying Supertonic engine |
model_dir | Path | Path to the model directory |
sample_rate | int | Audio sample rate in Hz |
voice_style_names | list[str] | List of available voice style names |
Example
Initialize the TTS engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing model files. If None, uses default cache directory | None |
auto_download | bool | If True, automatically downloads missing model files | True |
intra_op_num_threads | Optional[int] | Number of threads for intra-op parallelism. If None (default), ONNX Runtime automatically determines optimal value based on your system. Can also be set via SUPERTONIC_INTRA_OP_THREADS environment variable | None |
inter_op_num_threads | Optional[int] | Number of threads for inter-op parallelism. If None (default), ONNX Runtime automatically determines optimal value based on your system. Can also be set via SUPERTONIC_INTER_OP_THREADS environment variable | None |
Methods:
| Name | Description |
|---|---|
get_voice_style | Load a voice style by name. Avaliable voice style names can be listed with |
get_voice_style_from_path | Load a voice style from a JSON file path. |
synthesize | Synthesize speech from text. |
save_audio | Save synthesized audio to a WAV file. |
Source code in supertonic/pipeline.py
model instance-attribute ¶
model = load_model(
model_dir,
auto_download,
intra_op_num_threads,
inter_op_num_threads,
)
voice_style_names instance-attribute ¶
voice_style_names = list_available_voice_style_names(
model_dir
)
get_voice_style ¶
Load a voice style by name. Avaliable voice style names can be listed with list_available_voice_style_names().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voice_name | str | Name of the voice style (e.g., 'M1', 'F1', 'M2', 'F2') | required |
Returns:
| Type | Description |
|---|---|
Style | Style object containing voice style vectors |
Source code in supertonic/pipeline.py
get_voice_style_from_path ¶
Load a voice style from a JSON file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voice_style_path | Union[Path, str] | Path to the voice style JSON file (str or Path) | required |
Returns:
| Type | Description |
|---|---|
Style | Style object containing voice style vectors |
Source code in supertonic/pipeline.py
synthesize ¶
synthesize(
text: str,
voice_style: Style,
total_steps: int = DEFAULT_TOTAL_STEPS,
speed: float = DEFAULT_SPEED,
max_chunk_length: int = DEFAULT_MAX_CHUNK_LENGTH,
silence_duration: float = DEFAULT_SILENCE_DURATION,
verbose: bool = False,
) -> tuple[ndarray, ndarray]
Synthesize speech from text.
This method automatically chunks long text into smaller segments and concatenates them with silence in between.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Text to synthesize | required |
voice_style | Style | Voice style object | required |
total_steps | int | Number of synthesis steps (default: 5) | DEFAULT_TOTAL_STEPS |
speed | float | Speech speed multiplier (default: 1.05) | DEFAULT_SPEED |
max_chunk_length | int | Max characters per chunk (default: 300) | DEFAULT_MAX_CHUNK_LENGTH |
silence_duration | float | Silence between chunks in seconds (default: 0.3) | DEFAULT_SILENCE_DURATION |
verbose | bool | If True, print detailed progress information (default: False) | False |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray] | Tuple of (waveform, duration): - waveform: Audio array of shape (1, num_samples) - duration: Total duration in seconds |
Example
Source code in supertonic/pipeline.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
save_audio ¶
Save synthesized audio to a WAV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wav | ndarray | Audio waveform array from synthesize() | required |
output_path | str | Path where to save the WAV file | required |