Skip to content

supertonic.config

supertonic.config

Configuration and constants for Supertonic TTS package.

This module centralizes all configuration values, magic numbers, and default settings used throughout the package.

Functions:

Name Description
get_model_config

Get configuration for a specific model.

get_model_cache_dir

Get cache directory for a specific model.

get_model_repo

Get HuggingFace repo ID for a specific model.

get_model_revision

Get the HuggingFace Hub revision to download for a model.

is_multilingual_model

Check if a model supports multilingual synthesis.

Attributes:

Name Type Description
logger
AVAILABLE_MODELS
DEFAULT_MODEL
MODEL_CONFIGS
DEFAULT_MODEL_REPO
MODEL_REVISION_ENV_OVERRIDE
ONNX_DIR
VOICE_STYLES_DIR
CFG_REL_PATH
UNICODE_INDEXER_REL_PATH
DP_ONNX_REL_PATH
TEXT_ENC_ONNX_REL_PATH
VECTOR_EST_ONNX_REL_PATH
VOCODER_ONNX_REL_PATH
SUPPORTED_LANGUAGES
UNKNOWN_LANGUAGE
AVAILABLE_LANGUAGES
DEFAULT_LANGUAGE
DEFAULT_TOTAL_STEPS
DEFAULT_SPEED
DEFAULT_MAX_CHUNK_LENGTH
DEFAULT_MAX_CHUNK_LENGTH_KO
DEFAULT_SILENCE_DURATION
MIN_SPEED
MAX_SPEED
MIN_TOTAL_STEPS
MAX_TOTAL_STEPS
DEFAULT_ONNX_PROVIDERS
DEFAULT_INTRA_OP_NUM_THREADS
DEFAULT_INTER_OP_NUM_THREADS
MAX_TEXT_LENGTH
LOG_FORMAT
LOG_LEVEL

logger module-attribute

logger = getLogger(__name__)

AVAILABLE_MODELS module-attribute

AVAILABLE_MODELS = [
    "supertonic",
    "supertonic-2",
    "supertonic-3",
]

DEFAULT_MODEL module-attribute

DEFAULT_MODEL = 'supertonic-3'

MODEL_CONFIGS module-attribute

MODEL_CONFIGS = {
    "supertonic": {
        "repo": "Supertone/supertonic",
        "cache_dir": "supertonic",
        "multilingual": False,
        "revision": "b6856d033f622c63ea29441795be266a1133e227",
    },
    "supertonic-2": {
        "repo": "Supertone/supertonic-2",
        "cache_dir": "supertonic2",
        "multilingual": True,
        "revision": "75e6727618a02f323c720cba9478152d4bc16ca4",
    },
    "supertonic-3": {
        "repo": "Supertone/supertonic-3",
        "cache_dir": "supertonic3",
        "multilingual": True,
        "revision": "724fb5abbf5502583fb520898d45929e62f02c0b",
    },
}

DEFAULT_MODEL_REPO module-attribute

DEFAULT_MODEL_REPO = getenv(
    "SUPERTONIC_MODEL_REPO",
    MODEL_CONFIGS[DEFAULT_MODEL]["repo"],
)

MODEL_REVISION_ENV_OVERRIDE module-attribute

MODEL_REVISION_ENV_OVERRIDE = getenv(
    "SUPERTONIC_MODEL_REVISION"
)

get_model_config

get_model_config(model_name: str) -> dict

Get configuration for a specific model.

Parameters:

Name Type Description Default
model_name str

Model name (one of AVAILABLE_MODELS)

required

Returns:

Type Description
dict

Dictionary with model configuration (repo, cache_dir, multilingual)

Raises:

Type Description
ValueError

If model_name is not valid

Source code in supertonic/config.py
def get_model_config(model_name: str) -> dict:
    """Get configuration for a specific model.

    Args:
        model_name: Model name (one of ``AVAILABLE_MODELS``)

    Returns:
        Dictionary with model configuration (repo, cache_dir, multilingual)

    Raises:
        ValueError: If model_name is not valid
    """
    if model_name not in MODEL_CONFIGS:
        raise ValueError(
            f"Invalid model: '{model_name}'. " f"Available models: {', '.join(AVAILABLE_MODELS)}"
        )
    return MODEL_CONFIGS[model_name]

get_model_cache_dir

get_model_cache_dir(model_name: str) -> Path

Get cache directory for a specific model.

$SUPERTONIC_CACHE_DIR overrides the directory for every model when set — matching the documented contract and the historical DEFAULT_CACHE_DIR spelling. Users running two models from the same process and wanting them separated should leave the env var unset (each model then falls back to its own ~/.cache/<cache_dir>).

Parameters:

Name Type Description Default
model_name str

Model name (one of AVAILABLE_MODELS)

required

Returns:

Type Description
Path

Path to the model's cache directory

Source code in supertonic/config.py
def get_model_cache_dir(model_name: str) -> Path:
    """Get cache directory for a specific model.

    ``$SUPERTONIC_CACHE_DIR`` overrides the directory for *every* model when
    set — matching the documented contract and the historical
    ``DEFAULT_CACHE_DIR`` spelling. Users running two models from the same
    process and wanting them separated should leave the env var unset (each
    model then falls back to its own ``~/.cache/<cache_dir>``).

    Args:
        model_name: Model name (one of ``AVAILABLE_MODELS``)

    Returns:
        Path to the model's cache directory
    """
    env = os.environ.get("SUPERTONIC_CACHE_DIR")
    if env:
        return Path(env).expanduser()
    config = get_model_config(model_name)
    return Path.home() / ".cache" / config["cache_dir"]

get_model_repo

get_model_repo(model_name: str) -> str

Get HuggingFace repo ID for a specific model.

Parameters:

Name Type Description Default
model_name str

Model name (one of AVAILABLE_MODELS)

required

Returns:

Type Description
str

HuggingFace repository ID

Source code in supertonic/config.py
def get_model_repo(model_name: str) -> str:
    """Get HuggingFace repo ID for a specific model.

    Args:
        model_name: Model name (one of ``AVAILABLE_MODELS``)

    Returns:
        HuggingFace repository ID
    """
    config = get_model_config(model_name)
    return config["repo"]

get_model_revision

get_model_revision(model_name: str) -> str

Get the HuggingFace Hub revision to download for a model.

Priority: SUPERTONIC_MODEL_REVISION env var (if set) → the per-model pinned SHA in MODEL_CONFIGS. Pinning by SHA keeps a given package version reproducible across HF Hub updates.

Parameters:

Name Type Description Default
model_name str

Model name (one of AVAILABLE_MODELS)

required

Returns:

Type Description
str

Commit SHA (or whatever ref the env override points at).

Source code in supertonic/config.py
def get_model_revision(model_name: str) -> str:
    """Get the HuggingFace Hub revision to download for a model.

    Priority: ``SUPERTONIC_MODEL_REVISION`` env var (if set) → the
    per-model pinned SHA in ``MODEL_CONFIGS``. Pinning by SHA keeps a
    given package version reproducible across HF Hub updates.

    Args:
        model_name: Model name (one of ``AVAILABLE_MODELS``)

    Returns:
        Commit SHA (or whatever ref the env override points at).
    """
    if MODEL_REVISION_ENV_OVERRIDE:
        return MODEL_REVISION_ENV_OVERRIDE
    return get_model_config(model_name)["revision"]

is_multilingual_model

is_multilingual_model(model_name: str) -> bool

Check if a model supports multilingual synthesis.

Parameters:

Name Type Description Default
model_name str

Model name (one of AVAILABLE_MODELS)

required

Returns:

Type Description
bool

True if model supports multiple languages

Source code in supertonic/config.py
def is_multilingual_model(model_name: str) -> bool:
    """Check if a model supports multilingual synthesis.

    Args:
        model_name: Model name (one of ``AVAILABLE_MODELS``)

    Returns:
        True if model supports multiple languages
    """
    config = get_model_config(model_name)
    return config["multilingual"]

ONNX_DIR module-attribute

ONNX_DIR = Path('onnx')

VOICE_STYLES_DIR module-attribute

VOICE_STYLES_DIR = Path('voice_styles')

CFG_REL_PATH module-attribute

CFG_REL_PATH = ONNX_DIR / 'tts.json'

UNICODE_INDEXER_REL_PATH module-attribute

UNICODE_INDEXER_REL_PATH = ONNX_DIR / "unicode_indexer.json"

DP_ONNX_REL_PATH module-attribute

DP_ONNX_REL_PATH = ONNX_DIR / 'duration_predictor.onnx'

TEXT_ENC_ONNX_REL_PATH module-attribute

TEXT_ENC_ONNX_REL_PATH = ONNX_DIR / 'text_encoder.onnx'

VECTOR_EST_ONNX_REL_PATH module-attribute

VECTOR_EST_ONNX_REL_PATH = (
    ONNX_DIR / "vector_estimator.onnx"
)

VOCODER_ONNX_REL_PATH module-attribute

VOCODER_ONNX_REL_PATH = ONNX_DIR / 'vocoder.onnx'

SUPPORTED_LANGUAGES module-attribute

SUPPORTED_LANGUAGES = [
    "en",
    "ko",
    "ja",
    "ar",
    "bg",
    "cs",
    "da",
    "de",
    "el",
    "es",
    "et",
    "fi",
    "fr",
    "hi",
    "hr",
    "hu",
    "id",
    "it",
    "lt",
    "lv",
    "nl",
    "pl",
    "pt",
    "ro",
    "ru",
    "sk",
    "sl",
    "sv",
    "tr",
    "uk",
    "vi",
]

UNKNOWN_LANGUAGE module-attribute

UNKNOWN_LANGUAGE = 'na'

AVAILABLE_LANGUAGES module-attribute

AVAILABLE_LANGUAGES = SUPPORTED_LANGUAGES + [
    UNKNOWN_LANGUAGE
]

DEFAULT_LANGUAGE module-attribute

DEFAULT_LANGUAGE = 'en'

DEFAULT_TOTAL_STEPS module-attribute

DEFAULT_TOTAL_STEPS = 8

DEFAULT_SPEED module-attribute

DEFAULT_SPEED = 1.05

DEFAULT_MAX_CHUNK_LENGTH module-attribute

DEFAULT_MAX_CHUNK_LENGTH = 300

DEFAULT_MAX_CHUNK_LENGTH_KO module-attribute

DEFAULT_MAX_CHUNK_LENGTH_KO = 120

DEFAULT_SILENCE_DURATION module-attribute

DEFAULT_SILENCE_DURATION = 0.3

MIN_SPEED module-attribute

MIN_SPEED = 0.7

MAX_SPEED module-attribute

MAX_SPEED = 2.0

MIN_TOTAL_STEPS module-attribute

MIN_TOTAL_STEPS = 1

MAX_TOTAL_STEPS module-attribute

MAX_TOTAL_STEPS = 100

DEFAULT_ONNX_PROVIDERS module-attribute

DEFAULT_ONNX_PROVIDERS = ['CPUExecutionProvider']

DEFAULT_INTRA_OP_NUM_THREADS module-attribute

DEFAULT_INTRA_OP_NUM_THREADS = _parse_env_int(
    "SUPERTONIC_INTRA_OP_THREADS"
)

DEFAULT_INTER_OP_NUM_THREADS module-attribute

DEFAULT_INTER_OP_NUM_THREADS = _parse_env_int(
    "SUPERTONIC_INTER_OP_THREADS"
)

MAX_TEXT_LENGTH module-attribute

MAX_TEXT_LENGTH = 100000

LOG_FORMAT module-attribute

LOG_FORMAT = (
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)

LOG_LEVEL module-attribute

LOG_LEVEL = getenv('SUPERTONIC_LOG_LEVEL', 'INFO')