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: str = DEFAULT_MODEL,
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 | str | Model name to use ("supertonic" or "supertonic-2"). Default is "supertonic-2" (multilingual support). | DEFAULT_MODEL |
model_dir | Optional[Union[Path, str]] | Directory containing model files. If None, uses default cache directory based on model name. | 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_name | str | Name of the loaded model |
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 |
is_multilingual | bool | Whether the model supports multiple languages |
Example
from supertonic import TTS
# Use default model (supertonic-2 with multilingual support)
tts = TTS()
style = tts.get_voice_style("M1")
wav, dur = tts.synthesize("Hello!", voice_style=style, lang="en")
# Use specific model version
tts_v1 = TTS(model="supertonic") # English only
tts_v2 = TTS(model="supertonic-2") # Multilingual
Initialize the TTS engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | Model name ("supertonic" or "supertonic-2"). Default: "supertonic-2" | DEFAULT_MODEL |
model_dir | Union[Path, str] | Directory containing model files. If None, uses default cache directory based on model name | 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,
model,
)
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: Optional[int] = None,
silence_duration: float = DEFAULT_SILENCE_DURATION,
lang: str = DEFAULT_LANGUAGE,
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 | Optional[int] | Max characters per chunk. If None, automatically determined based on language (300 for most, 120 for Korean) | None |
silence_duration | float | Silence between chunks in seconds (default: 0.3) | DEFAULT_SILENCE_DURATION |
lang | str | Language code for synthesis. Supported languages: - "en": English (default) - "ko": Korean - "es": Spanish - "pt": Portuguese - "fr": French | DEFAULT_LANGUAGE |
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
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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
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 |