Implement standardized factory infrastructure enabling future engines: 1. ModelLoadConfig dataclass - Single canonical config class for all factories - Replaces duplicate UnifiedModelConfig - Contains device, model_name, language, model_path, repo_id, additional_params - Device resolution in __post_init__ for consistency 2. Engine capability registry - Data-driven engine specifications - Defines supports_voice_conversion, multilingual_model_switching, corruption recovery - Enables generic error handling without hardcoded engine checks - Covers all 7 TTS engines + IndexTTS-2 3. Fallback handler utility - Reusable fallback chain for graceful degradation - Try local → download → fallback language pattern - Eliminates duplicate fallback code across engines - Used by future engines automatically 4. Exception hierarchy - Standardized error types - TTSModelLoadingError base class - Specific types: NotFoundError, DeviceError, FormatError, InitializationError, LanguageNotSupportedError Architecture benefits: - All 8 factories now accept config: ModelLoadConfig instead of **kwargs - Type-safe, clear factory signatures - Future engines follow identical pattern - No deprecated code left behind - ComfyUI model manager handles both old and new patterns Testing: - All 7 TTS engines working correctly - Device switching and caching working - No syntax errors, all files compile Note: SmartModelLoader still in use (Tier 2 cleanup pending) causing benign double-loads on some engines.
93 lines
2.2 KiB
Python
93 lines
2.2 KiB
Python
"""
|
|
TTS Model Loading Exception Hierarchy
|
|
|
|
Standardized exceptions for all model loading operations across all TTS engines.
|
|
Provides consistent error handling and clear error messages to users and developers.
|
|
"""
|
|
|
|
|
|
class TTSModelLoadingError(Exception):
|
|
"""
|
|
Base exception for all TTS model loading errors.
|
|
|
|
All model loading failures inherit from this class, allowing callers to
|
|
catch all model-related errors with a single except clause.
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSModelNotFoundError(TTSModelLoadingError):
|
|
"""
|
|
Model file or repository not found.
|
|
|
|
Raised when:
|
|
- Local model files don't exist
|
|
- HuggingFace repository doesn't exist
|
|
- Model path is invalid
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSModelDownloadError(TTSModelLoadingError):
|
|
"""
|
|
Error downloading model from HuggingFace or remote source.
|
|
|
|
Raised when:
|
|
- Network request fails
|
|
- Repository is gated (requires authentication)
|
|
- Download is interrupted
|
|
- Insufficient disk space
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSDeviceError(TTSModelLoadingError):
|
|
"""
|
|
Device-related errors (CUDA, MPS, CPU issues).
|
|
|
|
Raised when:
|
|
- Device is unavailable
|
|
- Device VRAM is insufficient
|
|
- Device type is invalid
|
|
- Device-specific operations fail
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSModelFormatError(TTSModelLoadingError):
|
|
"""
|
|
Model format compatibility or loading issues.
|
|
|
|
Raised when:
|
|
- Model file format is unsupported
|
|
- Required model components are missing
|
|
- Model architecture is incompatible
|
|
- Weights can't be loaded into model
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSModelInitializationError(TTSModelLoadingError):
|
|
"""
|
|
Error initializing model after loading weights.
|
|
|
|
Raised when:
|
|
- Model initialization fails
|
|
- Required dependencies missing
|
|
- Configuration is invalid
|
|
- Post-load setup fails
|
|
"""
|
|
pass
|
|
|
|
|
|
class TTSLanguageNotSupportedError(TTSModelLoadingError):
|
|
"""
|
|
Language is not supported by this model or engine.
|
|
|
|
Raised when:
|
|
- Language model files don't exist
|
|
- Engine doesn't support requested language
|
|
- Language code is invalid
|
|
"""
|
|
pass
|