supertonic.loader¶
supertonic.loader ¶
Model loading and voice style management utilities.
This module handles downloading, loading, and managing Supertonic TTS models and voice styles from HuggingFace Hub.
Functions:
| Name | Description |
|---|---|
get_cache_dir | Get or create the default cache directory for Supertonic models. |
get_all_onnx_module_relative_paths | Get list of all required ONNX model file paths. |
has_all_onnx_modules | Check if all required ONNX model files exist in the directory. |
download_model | Download Supertonic model from HuggingFace Hub. |
load_configs | Load model configuration from JSON file. |
load_onnx_modules | Load all ONNX model modules for TTS synthesis. |
load_text_processor | Load the unicode text processor for the model. |
load_model | Load the complete Supertonic TTS model. |
list_available_voice_style_paths | List all available voice style JSON files in the model directory. |
list_available_voice_style_names | List names of all available voice styles. |
load_voice_style_from_json_file | Load a voice style from a JSON file. |
load_voice_style_from_name | Load a voice style by name from the model directory. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger | |
get_cache_dir ¶
get_cache_dir() -> Path
Get or create the default cache directory for Supertonic models.
Returns:
| Type | Description |
|---|---|
Path | Path object pointing to the cache directory |
Note
Default location is ~/.cache/supertonic, but can be overridden with SUPERTONIC_CACHE_DIR environment variable
Source code in supertonic/loader.py
get_all_onnx_module_relative_paths ¶
has_all_onnx_modules ¶
Check if all required ONNX model files exist in the directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory to check for model files (str or Path) | required |
Returns:
| Type | Description |
|---|---|
bool | True if all required ONNX files exist, False otherwise |
Source code in supertonic/loader.py
download_model ¶
Download Supertonic model from HuggingFace Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory where the model should be downloaded (str or Path) | required |
Source code in supertonic/loader.py
load_configs ¶
Load model configuration from JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the model files (str or Path) | required |
Returns:
| Type | Description |
|---|---|
dict | Dictionary containing model configuration |
Source code in supertonic/loader.py
load_onnx_modules ¶
load_onnx_modules(
model_dir: Union[Path, str],
intra_op_num_threads: Optional[int] = None,
inter_op_num_threads: Optional[int] = None,
) -> tuple[
InferenceSession,
InferenceSession,
InferenceSession,
InferenceSession,
]
Load all ONNX model modules for TTS synthesis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the ONNX model files (str or Path) | required |
intra_op_num_threads | Optional[int] | Number of threads for intra-op parallelism. None (default) lets ONNX Runtime auto-detect optimal value | None |
inter_op_num_threads | Optional[int] | Number of threads for inter-op parallelism. None (default) lets ONNX Runtime auto-detect optimal value | None |
Returns:
| Type | Description |
|---|---|
InferenceSession | Tuple of (duration_predictor, text_encoder, vector_estimator, vocoder) |
InferenceSession | ONNX Runtime inference sessions |
Source code in supertonic/loader.py
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 | |
load_text_processor ¶
load_text_processor(
model_dir: Union[Path, str],
) -> UnicodeProcessor
Load the unicode text processor for the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the model files (str or Path) | required |
Returns:
| Type | Description |
|---|---|
UnicodeProcessor | Initialized UnicodeProcessor instance |
Source code in supertonic/loader.py
load_model ¶
load_model(
model_dir: Union[Path, str],
auto_download: bool,
intra_op_num_threads: Optional[int] = None,
inter_op_num_threads: Optional[int] = None,
) -> Supertonic
Load the complete Supertonic TTS model.
This function loads all model components including ONNX modules, configuration, and text processor. If model files are missing and auto_download is enabled, it will download them from HuggingFace Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing (or to contain) the model files (str or Path) | required |
auto_download | bool | If True, automatically download missing model files | required |
intra_op_num_threads | Optional[int] | Number of threads for intra-op parallelism. None (default) lets ONNX Runtime auto-detect optimal value | None |
inter_op_num_threads | Optional[int] | Number of threads for inter-op parallelism. None (default) lets ONNX Runtime auto-detect optimal value | None |
Returns:
| Type | Description |
|---|---|
Supertonic | Initialized Supertonic TTS engine |
Source code in supertonic/loader.py
list_available_voice_style_paths ¶
List all available voice style JSON files in the model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the model files (str or Path) | required |
Returns:
| Type | Description |
|---|---|
list[Path] | Sorted list of paths to voice style JSON files |
Source code in supertonic/loader.py
list_available_voice_style_names ¶
List names of all available voice styles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the model files (str or Path) | required |
Returns:
| Type | Description |
|---|---|
list[str] | List of voice style names (without .json extension) |
Source code in supertonic/loader.py
load_voice_style_from_json_file ¶
Load a voice style from a JSON file.
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 with loaded style vectors |
Source code in supertonic/loader.py
load_voice_style_from_name ¶
Load a voice style by name from the model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir | Union[Path, str] | Directory containing the model files (str or Path) | required |
voice_name | str | Name of the voice style (without .json extension) | required |
Returns:
| Type | Description |
|---|---|
Style | Style object with loaded style vectors |