mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Merge pull request #177 from k0sm0naft/refactor/tts-backend-interface
feat: Add TTSBackendMetadata model
This commit is contained in:
+23
-1
@@ -1,12 +1,30 @@
|
||||
"""
|
||||
TTS Backend Interface
|
||||
|
||||
This module defines the protocol for TTS backends.
|
||||
This module defines the protocol for TTS backends and the
|
||||
metadata model that describes a backend implementation.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Protocol, List, Dict, Any
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TTSBackendMetadata:
|
||||
"""
|
||||
Immutable metadata describing a TTS backend implementation.
|
||||
|
||||
Attributes:
|
||||
id: Unique backend identifier (e.g. ``"kokoro"``, ``"supertonic"``).
|
||||
name: Human-readable display name.
|
||||
description: Short description of the backend.
|
||||
"""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
description: str
|
||||
|
||||
|
||||
class TTSBackend(Protocol):
|
||||
"""
|
||||
Protocol for TTS backends.
|
||||
@@ -15,6 +33,10 @@ class TTSBackend(Protocol):
|
||||
with the application.
|
||||
"""
|
||||
|
||||
@property
|
||||
def metadata(self) -> TTSBackendMetadata:
|
||||
...
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
"""
|
||||
Initialize the TTS backend.
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from abogen.tts_backend import TTSBackendMetadata
|
||||
|
||||
|
||||
class TestTTSBackendMetadata:
|
||||
def test_is_frozen_dataclass(self):
|
||||
assert dataclass(TTSBackendMetadata)
|
||||
|
||||
def test_fields_are_present(self):
|
||||
meta = TTSBackendMetadata(
|
||||
id="test",
|
||||
name="Test Backend",
|
||||
description="A test backend",
|
||||
)
|
||||
assert meta.id == "test"
|
||||
assert meta.name == "Test Backend"
|
||||
assert meta.description == "A test backend"
|
||||
|
||||
def test_is_immutable(self):
|
||||
import pytest
|
||||
|
||||
meta = TTSBackendMetadata(
|
||||
id="kokoro",
|
||||
name="Kokoro",
|
||||
description="Test",
|
||||
)
|
||||
with pytest.raises(Exception):
|
||||
meta.id = "changed"
|
||||
Reference in New Issue
Block a user