mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
feat: add static voice catalog to PluginManifest
- Add to PluginManifest - None = not declared (use VoiceLister fallback) - () = explicitly no static voices - Non-empty = static catalog available without Engine instantiation - Update get_voices() to check manifest first, fall back to Engine - Declare 54 Kokoro voices and 10 SuperTonic voices in manifests - Remove hardcoded voice lists from engine.py files - Engine.listVoices() now returns [] (manifest is source of truth) - Clean up dead create_pipeline() kwargs (sample_rate, auto_download, total_steps) - SuperTonic plugin uses internal defaults - total_steps is per-request parameter via Pipeline.__call__() kwargs - Add clear_preview_pipelines() for resource cleanup - Fix test mocks to override listVoices() - Update Architecture Amendment #1 doc
This commit is contained in:
@@ -173,6 +173,8 @@ class PluginManifest:
|
|||||||
capabilities: List of capability identifiers.
|
capabilities: List of capability identifiers.
|
||||||
requires: Plugin requirements.
|
requires: Plugin requirements.
|
||||||
engine: Engine manifest.
|
engine: Engine manifest.
|
||||||
|
voices: Optional static voice catalog. None = not declared (use VoiceLister),
|
||||||
|
empty tuple = explicitly no static voices, non-empty = static catalog.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
@@ -184,3 +186,4 @@ class PluginManifest:
|
|||||||
capabilities: tuple[str, ...] = field(default_factory=tuple)
|
capabilities: tuple[str, ...] = field(default_factory=tuple)
|
||||||
requires: RequirementManifest = field(default_factory=RequirementManifest)
|
requires: RequirementManifest = field(default_factory=RequirementManifest)
|
||||||
engine: EngineManifest = field(default_factory=EngineManifest)
|
engine: EngineManifest = field(default_factory=EngineManifest)
|
||||||
|
voices: tuple[VoiceManifest, ...] | None = None
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ calling the Plugin Manager directly.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Iterator, Optional
|
from typing import Any, Iterator
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ def get_voices(plugin_id: str) -> tuple[str, ...]:
|
|||||||
"""Return the voice-id tuple for *plugin_id*.
|
"""Return the voice-id tuple for *plugin_id*.
|
||||||
|
|
||||||
Uses the official Plugin Architecture: PluginManager → Engine → VoiceLister.
|
Uses the official Plugin Architecture: PluginManager → Engine → VoiceLister.
|
||||||
|
First checks plugin manifest for static voice catalog.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -29,6 +30,13 @@ def get_voices(plugin_id: str) -> tuple[str, ...]:
|
|||||||
if not manager.has_plugin(plugin_id):
|
if not manager.has_plugin(plugin_id):
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
# Check manifest for static voice catalog
|
||||||
|
plugin_info = manager.get_plugin(plugin_id)
|
||||||
|
if plugin_info is not None:
|
||||||
|
manifest = plugin_info.get("manifest")
|
||||||
|
if manifest is not None and manifest.voices is not None:
|
||||||
|
return tuple(v.id for v in manifest.voices)
|
||||||
|
|
||||||
ctx = HostContext(
|
ctx = HostContext(
|
||||||
config_dir=Path(tempfile.gettempdir()),
|
config_dir=Path(tempfile.gettempdir()),
|
||||||
logger=logging.getLogger(f"abogen.utils.{plugin_id}"),
|
logger=logging.getLogger(f"abogen.utils.{plugin_id}"),
|
||||||
@@ -183,12 +191,45 @@ class Pipeline:
|
|||||||
self.dispose()
|
self.dispose()
|
||||||
|
|
||||||
|
|
||||||
def create_pipeline(plugin_id: str, **kwargs: Any) -> Pipeline:
|
def create_pipeline(
|
||||||
|
plugin_id: str,
|
||||||
|
*,
|
||||||
|
lang_code: str = "a",
|
||||||
|
device: str = "cpu",
|
||||||
|
) -> Pipeline:
|
||||||
"""Create a callable TTS pipeline via the Plugin Architecture.
|
"""Create a callable TTS pipeline via the Plugin Architecture.
|
||||||
|
|
||||||
Returns a :class:`Pipeline` whose ``__call__`` interface matches the
|
Builds a proper HostContext and EngineConfig, then delegates to the
|
||||||
legacy ``TTSBackend`` callable protocol.
|
PluginManager to create the engine. Returns a :class:`Pipeline` whose
|
||||||
|
``__call__`` interface matches the legacy ``TTSBackend`` callable protocol.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
plugin_id: Plugin identifier (e.g., "kokoro", "supertonic").
|
||||||
|
lang_code: Language code for the engine.
|
||||||
|
device: Device to use (e.g., "cpu", "cuda:0").
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A callable Pipeline instance.
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from abogen.tts_plugin.host_context import HostContext
|
||||||
|
from abogen.tts_plugin.types import EngineConfig
|
||||||
|
|
||||||
manager = get_plugin_manager()
|
manager = get_plugin_manager()
|
||||||
engine = manager.create_engine(plugin_id, **kwargs)
|
|
||||||
return Pipeline(engine, **kwargs)
|
ctx = HostContext(
|
||||||
|
config_dir=Path(tempfile.gettempdir()),
|
||||||
|
logger=logging.getLogger(f"abogen.pipeline.{plugin_id}"),
|
||||||
|
http_client=type("_StubHttpClient", (), {
|
||||||
|
"get": staticmethod(lambda url, **kw: None),
|
||||||
|
"post": staticmethod(lambda url, **kw: None),
|
||||||
|
})(),
|
||||||
|
)
|
||||||
|
|
||||||
|
config = EngineConfig(device=device, lang_code=lang_code)
|
||||||
|
|
||||||
|
engine = manager.create_engine(plugin_id, context=ctx, model_path=None, config=config)
|
||||||
|
return Pipeline(engine)
|
||||||
|
|||||||
@@ -1576,9 +1576,6 @@ def run_conversion_job(job: Job) -> None:
|
|||||||
if provider_norm == "supertonic":
|
if provider_norm == "supertonic":
|
||||||
pipelines[provider_norm] = create_pipeline(
|
pipelines[provider_norm] = create_pipeline(
|
||||||
"supertonic",
|
"supertonic",
|
||||||
sample_rate=SAMPLE_RATE,
|
|
||||||
auto_download=True,
|
|
||||||
total_steps=int(getattr(job, "supertonic_total_steps", 5) or 5),
|
|
||||||
)
|
)
|
||||||
return pipelines[provider_norm]
|
return pipelines[provider_norm]
|
||||||
|
|
||||||
@@ -2408,6 +2405,11 @@ def run_conversion_job(job: Job) -> None:
|
|||||||
|
|
||||||
# Explicitly release the pipeline and force garbage collection to prevent
|
# Explicitly release the pipeline and force garbage collection to prevent
|
||||||
# memory accumulation in the worker process, which can lead to host lockups.
|
# memory accumulation in the worker process, which can lead to host lockups.
|
||||||
|
for p in pipelines.values():
|
||||||
|
try:
|
||||||
|
p.dispose()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
pipelines.clear()
|
pipelines.clear()
|
||||||
pipeline = None
|
pipeline = None
|
||||||
gc.collect()
|
gc.collect()
|
||||||
@@ -2443,9 +2445,6 @@ def _load_pipeline(job: Job):
|
|||||||
if provider == "supertonic":
|
if provider == "supertonic":
|
||||||
return create_pipeline(
|
return create_pipeline(
|
||||||
"supertonic",
|
"supertonic",
|
||||||
sample_rate=SAMPLE_RATE,
|
|
||||||
auto_download=True,
|
|
||||||
total_steps=int(getattr(job, "supertonic_total_steps", 5) or 5),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
device = "cpu"
|
device = "cpu"
|
||||||
|
|||||||
@@ -14,6 +14,17 @@ _preview_pipelines: Dict[Tuple[str, str], Any] = {}
|
|||||||
_preview_pipeline_lock = threading.Lock()
|
_preview_pipeline_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
def clear_preview_pipelines() -> None:
|
||||||
|
"""Dispose all cached preview pipelines and clear the cache."""
|
||||||
|
with _preview_pipeline_lock:
|
||||||
|
for pipeline in _preview_pipelines.values():
|
||||||
|
try:
|
||||||
|
pipeline.dispose()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
_preview_pipelines.clear()
|
||||||
|
|
||||||
|
|
||||||
def _select_device() -> str:
|
def _select_device() -> str:
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
@@ -138,7 +149,7 @@ def generate_preview_audio(
|
|||||||
if provider == "supertonic":
|
if provider == "supertonic":
|
||||||
from abogen.tts_plugin.utils import create_pipeline
|
from abogen.tts_plugin.utils import create_pipeline
|
||||||
|
|
||||||
pipeline = create_pipeline("supertonic", sample_rate=SAMPLE_RATE, auto_download=True, total_steps=supertonic_total_steps)
|
pipeline = create_pipeline("supertonic")
|
||||||
segments = pipeline(
|
segments = pipeline(
|
||||||
normalized_text,
|
normalized_text,
|
||||||
voice=voice_spec,
|
voice=voice_spec,
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# Architecture Amendment #1: EngineConfig — `lang_code` field
|
||||||
|
|
||||||
|
**Date:** 2026-07-12
|
||||||
|
**Status:** Accepted
|
||||||
|
**PR:** #12 (Normalize Pipeline Public API)
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Add `lang_code: str = "a"` to `EngineConfig` and update its definition to clarify the architectural contract.
|
||||||
|
|
||||||
|
## Background
|
||||||
|
|
||||||
|
During migration from the old `KokoroBackend` to the Plugin Architecture, the `lang_code` parameter became a dead argument. The old backend read it from `**kwargs` and passed it to `KPipeline(lang_code=...)`. The new `KokoroPlugin.create_engine()` hardcodes `lang_code="a"`, ignoring the config entirely. Callers continued passing `lang_code` to `create_pipeline()`, unaware it had no effect.
|
||||||
|
|
||||||
|
This is a functional regression relative to the pre-Plugin Architecture behavior.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
### 1. Updated EngineConfig definition
|
||||||
|
|
||||||
|
**Before:**
|
||||||
|
```
|
||||||
|
Immutable value object for engine initialization settings.
|
||||||
|
Contains only engine-specific settings, no resource references.
|
||||||
|
```
|
||||||
|
|
||||||
|
**After:**
|
||||||
|
```
|
||||||
|
Immutable configuration of an Engine instance.
|
||||||
|
Contains parameters that define how a particular Engine instance is
|
||||||
|
created and that remain constant throughout the lifetime of that Engine.
|
||||||
|
Plugin implementations may ignore fields that are not applicable to them.
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. New field
|
||||||
|
|
||||||
|
```python
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class EngineConfig:
|
||||||
|
device: str = "cpu"
|
||||||
|
lang_code: str = "a"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Architectural rules
|
||||||
|
|
||||||
|
- **Fields in EngineConfig are optional unless explicitly required by a plugin.**
|
||||||
|
- **Plugins MUST ignore unsupported EngineConfig fields.**
|
||||||
|
- **All parameters that may vary between individual synthesis requests must remain in `SynthesisRequest.parameters`.**
|
||||||
|
|
||||||
|
## Rationale
|
||||||
|
|
||||||
|
Analysis of real TTS engines (Kokoro, Piper, XTTS, Coqui, StyleTTS2, Fish Speech) confirmed:
|
||||||
|
|
||||||
|
| Parameter type | Where it belongs | Example |
|
||||||
|
|---------------|-----------------|---------|
|
||||||
|
| Engine instance config (immutable) | `EngineConfig` | `device`, `lang_code` |
|
||||||
|
| Synthesis parameters (per-request) | `SynthesisRequest.parameters` | `speed`, `split_pattern`, `total_steps` |
|
||||||
|
|
||||||
|
`lang_code` determines the engine's behavior at creation time and cannot be changed during the engine's lifetime. It is not a synthesis parameter.
|
||||||
|
|
||||||
|
## Impact on existing plugins
|
||||||
|
|
||||||
|
| Plugin | `device` | `lang_code` | Notes |
|
||||||
|
|--------|----------|-------------|-------|
|
||||||
|
| Kokoro | Reads ✓ | Reads ✓ (was hardcoded, now from config) | Regression fixed |
|
||||||
|
| SuperTonic | Ignores | Ignores | No change — no language concept |
|
||||||
|
| Future plugins | May read | May ignore | Field-ignoring rule applies |
|
||||||
|
|
||||||
|
## Contract tests added
|
||||||
|
|
||||||
|
```python
|
||||||
|
class TestEngineConfigContract:
|
||||||
|
def test_default_lang_code(self) # EngineConfig().lang_code == "a"
|
||||||
|
def test_custom_lang_code(self) # EngineConfig(lang_code="j").lang_code == "j"
|
||||||
|
def test_immutability_lang_code(self) # frozen — cannot reassign
|
||||||
|
def test_plugins_may_ignore_irrelevant_fields(self) # field-ignoring rule
|
||||||
|
def test_engine_config_contains_engine_instance_configuration(self) # definition
|
||||||
|
```
|
||||||
|
|
||||||
|
## Files changed
|
||||||
|
|
||||||
|
| File | Change |
|
||||||
|
|------|--------|
|
||||||
|
| `abogen/tts_plugin/types.py` | Updated docstring, added `lang_code: str = "a"` |
|
||||||
|
| `plugins/kokoro/__init__.py` | Reads `config.lang_code` instead of hardcoded `"a"` |
|
||||||
|
| `abogen/tts_plugin/utils.py` | `create_pipeline()` passes `lang_code` to `EngineConfig` |
|
||||||
|
| `tests/contracts/test_types_contract.py` | 5 new contract tests |
|
||||||
|
| `tests/contracts/test_plugin_manager_contract.py` | Updated assertion for `lang_code` |
|
||||||
|
| `tests/test_behavioral_regression.py` | Updated `test_engine_config_defaults` |
|
||||||
@@ -24,6 +24,7 @@ from abogen.tts_plugin.manifest import (
|
|||||||
ParameterManifest,
|
ParameterManifest,
|
||||||
PluginManifest,
|
PluginManifest,
|
||||||
RequirementManifest,
|
RequirementManifest,
|
||||||
|
VoiceManifest,
|
||||||
VoiceSourceManifest,
|
VoiceSourceManifest,
|
||||||
)
|
)
|
||||||
from abogen.tts_plugin.types import EngineConfig
|
from abogen.tts_plugin.types import EngineConfig
|
||||||
@@ -73,6 +74,62 @@ PLUGIN_MANIFEST = PluginManifest(
|
|||||||
AudioFormatManifest(mime="audio/wav", extension="wav"),
|
AudioFormatManifest(mime="audio/wav", extension="wav"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
voices=(
|
||||||
|
VoiceManifest(id="af_alloy", name="Alloy", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_aoede", name="Aoede", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_bella", name="Bella", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_heart", name="Heart", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_jessica", name="Jessica", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_kore", name="Kore", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_nicole", name="Nicole", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_nova", name="Nova", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_river", name="River", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_sarah", name="Sarah", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="af_sky", name="Sky", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="am_adam", name="Adam", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_echo", name="Echo", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_eric", name="Eric", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_fenrir", name="Fenrir", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_liam", name="Liam", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_michael", name="Michael", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_onyx", name="Onyx", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_puck", name="Puck", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="am_santa", name="Santa", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="bf_alice", name="Alice", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="bf_emma", name="Emma", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="bf_isabella", name="Isabella", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="bf_lily", name="Lily", tags=("en", "female")),
|
||||||
|
VoiceManifest(id="bm_daniel", name="Daniel", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="bm_fable", name="Fable", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="bm_george", name="George", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="bm_lewis", name="Lewis", tags=("en", "male")),
|
||||||
|
VoiceManifest(id="ef_dora", name="Dora", tags=("es", "female")),
|
||||||
|
VoiceManifest(id="em_alex", name="Alex", tags=("es", "male")),
|
||||||
|
VoiceManifest(id="em_santa", name="Santa", tags=("es", "male")),
|
||||||
|
VoiceManifest(id="ff_siwis", name="Siwis", tags=("fr", "female")),
|
||||||
|
VoiceManifest(id="hf_alpha", name="Alpha", tags=("hi", "female")),
|
||||||
|
VoiceManifest(id="hf_beta", name="Beta", tags=("hi", "female")),
|
||||||
|
VoiceManifest(id="hm_omega", name="Omega", tags=("hi", "male")),
|
||||||
|
VoiceManifest(id="hm_psi", name="Psi", tags=("hi", "male")),
|
||||||
|
VoiceManifest(id="if_sara", name="Sara", tags=("it", "female")),
|
||||||
|
VoiceManifest(id="im_nicola", name="Nicola", tags=("it", "male")),
|
||||||
|
VoiceManifest(id="jf_alpha", name="Alpha", tags=("ja", "female")),
|
||||||
|
VoiceManifest(id="jf_gongitsune", name="Gongitsune", tags=("ja", "female")),
|
||||||
|
VoiceManifest(id="jf_nezumi", name="Nezumi", tags=("ja", "female")),
|
||||||
|
VoiceManifest(id="jf_tebukuro", name="Tebukuro", tags=("ja", "female")),
|
||||||
|
VoiceManifest(id="jm_kumo", name="Kumo", tags=("ja", "male")),
|
||||||
|
VoiceManifest(id="pf_dora", name="Dora", tags=("pt", "female")),
|
||||||
|
VoiceManifest(id="pm_alex", name="Alex", tags=("pt", "male")),
|
||||||
|
VoiceManifest(id="pm_santa", name="Santa", tags=("pt", "male")),
|
||||||
|
VoiceManifest(id="zf_xiaobei", name="Xiaobei", tags=("zh", "female")),
|
||||||
|
VoiceManifest(id="zf_xiaoni", name="Xiaoni", tags=("zh", "female")),
|
||||||
|
VoiceManifest(id="zf_xiaoxiao", name="Xiaoxiao", tags=("zh", "female")),
|
||||||
|
VoiceManifest(id="zf_xiaoyi", name="Xiaoyi", tags=("zh", "female")),
|
||||||
|
VoiceManifest(id="zm_yunjian", name="Yunjian", tags=("zh", "male")),
|
||||||
|
VoiceManifest(id="zm_yunxi", name="Yunxi", tags=("zh", "male")),
|
||||||
|
VoiceManifest(id="zm_yunxia", name="Yunxia", tags=("zh", "female")),
|
||||||
|
VoiceManifest(id="zm_yunyang", name="Yunyang", tags=("zh", "male")),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
MODEL_REQUIREMENTS: list[ModelManifest] = []
|
MODEL_REQUIREMENTS: list[ModelManifest] = []
|
||||||
@@ -109,12 +166,12 @@ def create_engine(
|
|||||||
repo_id = str(model_path)
|
repo_id = str(model_path)
|
||||||
|
|
||||||
pipeline = KPipeline(
|
pipeline = KPipeline(
|
||||||
lang_code="a", # Default language code
|
lang_code=config.lang_code,
|
||||||
repo_id=repo_id,
|
repo_id=repo_id,
|
||||||
device=config.device,
|
device=config.device,
|
||||||
)
|
)
|
||||||
|
|
||||||
engine = KokoroEngine(pipeline, lang_code="a")
|
engine = KokoroEngine(pipeline)
|
||||||
return engine
|
return engine
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
from abogen.tts_plugin.errors import EngineError as EngineErrorClass
|
from abogen.tts_plugin.errors import EngineError as EngineErrorClass
|
||||||
|
|||||||
+11
-79
@@ -7,66 +7,23 @@ protocol. It wraps the KokoroBackend without modifying it.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Iterator
|
from typing import Any
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from abogen.tts_plugin.capabilities import VoiceLister
|
from abogen.tts_plugin.capabilities import VoiceLister
|
||||||
from abogen.tts_plugin.engine import Engine, EngineSession
|
from abogen.tts_plugin.engine import Engine, EngineSession
|
||||||
from abogen.tts_plugin.errors import EngineError, InvalidInputError
|
from abogen.tts_plugin.errors import EngineError
|
||||||
from abogen.tts_plugin.manifest import VoiceManifest
|
from abogen.tts_plugin.manifest import VoiceManifest
|
||||||
from abogen.tts_plugin.types import (
|
from abogen.tts_plugin.types import (
|
||||||
AudioFormat,
|
AudioFormat,
|
||||||
Duration,
|
Duration,
|
||||||
ParameterValues,
|
|
||||||
SynthesisRequest,
|
SynthesisRequest,
|
||||||
SynthesizedAudio,
|
SynthesizedAudio,
|
||||||
VoiceSelection,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Kokoro voice list - source of truth
|
|
||||||
_KOKORO_VOICES = (
|
|
||||||
"af_alloy", "af_aoede", "af_bella", "af_heart", "af_jessica",
|
|
||||||
"af_kore", "af_nicole", "af_nova", "af_river", "af_sarah",
|
|
||||||
"af_sky", "am_adam", "am_echo", "am_eric", "am_fenrir",
|
|
||||||
"am_liam", "am_michael", "am_onyx", "am_puck", "am_santa",
|
|
||||||
"bf_alice", "bf_emma", "bf_isabella", "bf_lily",
|
|
||||||
"bm_daniel", "bm_fable", "bm_george", "bm_lewis",
|
|
||||||
"ef_dora", "em_alex", "em_santa",
|
|
||||||
"ff_siwis", "hf_alpha", "hf_beta", "hm_omega", "hm_psi",
|
|
||||||
"if_sara", "im_nicola",
|
|
||||||
"jf_alpha", "jf_gongitsune", "jf_nezumi", "jf_tebukuro", "jm_kumo",
|
|
||||||
"pf_dora", "pm_alex", "pm_santa",
|
|
||||||
"zf_xiaobei", "zf_xiaoni", "zf_xiaoxiao", "zf_xiaoyi",
|
|
||||||
"zm_yunjian", "zm_yunxi", "zm_yunxia", "zm_yunyang",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Voice display names mapping
|
|
||||||
_VOICE_DISPLAY_NAMES: dict[str, str] = {
|
|
||||||
"af_alloy": "Alloy", "af_aoede": "Aoede", "af_bella": "Bella",
|
|
||||||
"af_heart": "Heart", "af_jessica": "Jessica", "af_kore": "Kore",
|
|
||||||
"af_nicole": "Nicole", "af_nova": "Nova", "af_river": "River",
|
|
||||||
"af_sarah": "Sarah", "af_sky": "Sky", "am_adam": "Adam",
|
|
||||||
"am_echo": "Echo", "am_eric": "Eric", "am_fenrir": "Fenrir",
|
|
||||||
"am_liam": "Liam", "am_michael": "Michael", "am_onyx": "Onyx",
|
|
||||||
"am_puck": "Puck", "am_santa": "Santa", "bf_alice": "Alice",
|
|
||||||
"bf_emma": "Emma", "bf_isabella": "Isabella", "bf_lily": "Lily",
|
|
||||||
"bm_daniel": "Daniel", "bm_fable": "Fable", "bm_george": "George",
|
|
||||||
"bm_lewis": "Lewis", "ef_dora": "Dora", "em_alex": "Alex",
|
|
||||||
"em_santa": "Santa", "ff_siwis": "Siwis", "hf_alpha": "Alpha",
|
|
||||||
"hf_beta": "Beta", "hm_omega": "Omega", "hm_psi": "Psi",
|
|
||||||
"if_sara": "Sara", "im_nicola": "Nicola",
|
|
||||||
"jf_alpha": "Alpha", "jf_gongitsune": "Gongitsune",
|
|
||||||
"jf_nezumi": "Nezumi", "jf_tebukuro": "Tebukuro", "jm_kumo": "Kumo",
|
|
||||||
"pf_dora": "Dora", "pm_alex": "Alex", "pm_santa": "Santa",
|
|
||||||
"zf_xiaobei": "Xiaobei", "zf_xiaoni": "Xiaoni",
|
|
||||||
"zf_xiaoxiao": "Xiaoxiao", "zf_xiaoyi": "Xiaoyi",
|
|
||||||
"zm_yunjian": "Yunjian", "zm_yunxi": "Yunxi",
|
|
||||||
"zm_yunxia": "Yunxia", "zm_yunyang": "Yunyang",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sample rate for Kokoro audio
|
# Sample rate for Kokoro audio
|
||||||
_KOKORO_SAMPLE_RATE = 24000
|
_KOKORO_SAMPLE_RATE = 24000
|
||||||
|
|
||||||
@@ -78,9 +35,8 @@ class KokoroSession:
|
|||||||
NOT thread-safe.
|
NOT thread-safe.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, pipeline: Any, lang_code: str) -> None:
|
def __init__(self, pipeline: Any) -> None:
|
||||||
self._pipeline = pipeline
|
self._pipeline = pipeline
|
||||||
self._lang_code = lang_code
|
|
||||||
self._disposed = False
|
self._disposed = False
|
||||||
|
|
||||||
def synthesize(self, request: SynthesisRequest) -> SynthesizedAudio:
|
def synthesize(self, request: SynthesisRequest) -> SynthesizedAudio:
|
||||||
@@ -137,50 +93,26 @@ class KokoroEngine:
|
|||||||
Factory for KokoroSession instances. Stateless and thread-safe.
|
Factory for KokoroSession instances. Stateless and thread-safe.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, pipeline: Any, lang_code: str) -> None:
|
def __init__(self, pipeline: Any) -> None:
|
||||||
self._pipeline = pipeline
|
self._pipeline = pipeline
|
||||||
self._lang_code = lang_code
|
|
||||||
self._disposed = False
|
self._disposed = False
|
||||||
|
|
||||||
def createSession(self) -> KokoroSession:
|
def createSession(self) -> KokoroSession:
|
||||||
"""Create a new KokoroSession."""
|
"""Create a new KokoroSession."""
|
||||||
if self._disposed:
|
if self._disposed:
|
||||||
raise EngineError("Engine disposed")
|
raise EngineError("Engine disposed")
|
||||||
return KokoroSession(self._pipeline, self._lang_code)
|
return KokoroSession(self._pipeline)
|
||||||
|
|
||||||
def dispose(self) -> None:
|
def dispose(self) -> None:
|
||||||
"""Release engine resources. Idempotent."""
|
"""Release engine resources. Idempotent."""
|
||||||
self._disposed = True
|
self._disposed = True
|
||||||
|
|
||||||
def listVoices(self, sourceId: str) -> list[VoiceManifest]:
|
def listVoices(self, sourceId: str) -> list[VoiceManifest]:
|
||||||
"""List available Kokoro voices. Implements VoiceLister capability."""
|
"""List available Kokoro voices. Implements VoiceLister capability.
|
||||||
|
|
||||||
|
Note: Static voices are declared in the plugin manifest.
|
||||||
|
This method is a fallback for dynamic plugins.
|
||||||
|
"""
|
||||||
if self._disposed:
|
if self._disposed:
|
||||||
raise EngineError("Engine disposed")
|
raise EngineError("Engine disposed")
|
||||||
return [
|
return []
|
||||||
VoiceManifest(
|
|
||||||
id=voice_id,
|
|
||||||
name=_VOICE_DISPLAY_NAMES.get(voice_id, voice_id),
|
|
||||||
tags=(_get_language_tag(voice_id), _get_gender_tag(voice_id)),
|
|
||||||
)
|
|
||||||
for voice_id in _KOKORO_VOICES
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _get_language_tag(voice_id: str) -> str:
|
|
||||||
"""Extract language tag from voice ID."""
|
|
||||||
prefix = voice_id.split("_")[0]
|
|
||||||
lang_map = {
|
|
||||||
"af": "en-us", "am": "en-us", "bf": "en-gb", "bm": "en-gb",
|
|
||||||
"ef": "es", "em": "es", "ff": "fr", "hf": "hi", "hm": "hi",
|
|
||||||
"if": "it", "im": "it", "jf": "ja", "jm": "ja",
|
|
||||||
"pf": "pt", "pm": "pt", "zf": "zh", "zm": "zh",
|
|
||||||
}
|
|
||||||
return lang_map.get(prefix, "unknown")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_gender_tag(voice_id: str) -> str:
|
|
||||||
"""Extract gender tag from voice ID."""
|
|
||||||
prefix = voice_id.split("_")[0]
|
|
||||||
if prefix.startswith("a") or prefix.startswith("b") or prefix.startswith("e"):
|
|
||||||
return "female" if prefix[1] == "f" else "male"
|
|
||||||
return "unknown"
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from abogen.tts_plugin.manifest import (
|
|||||||
ParameterManifest,
|
ParameterManifest,
|
||||||
PluginManifest,
|
PluginManifest,
|
||||||
RequirementManifest,
|
RequirementManifest,
|
||||||
|
VoiceManifest,
|
||||||
VoiceSourceManifest,
|
VoiceSourceManifest,
|
||||||
)
|
)
|
||||||
from abogen.tts_plugin.types import EngineConfig
|
from abogen.tts_plugin.types import EngineConfig
|
||||||
@@ -31,14 +32,14 @@ from abogen.tts_plugin.types import EngineConfig
|
|||||||
from .engine import SuperTonicEngine
|
from .engine import SuperTonicEngine
|
||||||
|
|
||||||
|
|
||||||
def _load_supertonic_pipeline(sample_rate: int = 24000, auto_download: bool = True, total_steps: int = 5) -> Any:
|
def _load_supertonic_pipeline() -> Any:
|
||||||
"""Lazy-load SuperTonic dependencies and create pipeline."""
|
"""Lazy-load SuperTonic dependencies and create pipeline."""
|
||||||
from plugins.supertonic.pipeline import SupertonicPipeline
|
from plugins.supertonic.pipeline import SupertonicPipeline
|
||||||
|
|
||||||
return SupertonicPipeline(
|
return SupertonicPipeline(
|
||||||
sample_rate=sample_rate,
|
sample_rate=24000,
|
||||||
auto_download=auto_download,
|
auto_download=True,
|
||||||
total_steps=total_steps,
|
total_steps=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +89,18 @@ PLUGIN_MANIFEST = PluginManifest(
|
|||||||
AudioFormatManifest(mime="audio/wav", extension="wav"),
|
AudioFormatManifest(mime="audio/wav", extension="wav"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
voices=(
|
||||||
|
VoiceManifest(id="M1", name="Male 1", tags=("male",)),
|
||||||
|
VoiceManifest(id="M2", name="Male 2", tags=("male",)),
|
||||||
|
VoiceManifest(id="M3", name="Male 3", tags=("male",)),
|
||||||
|
VoiceManifest(id="M4", name="Male 4", tags=("male",)),
|
||||||
|
VoiceManifest(id="M5", name="Male 5", tags=("male",)),
|
||||||
|
VoiceManifest(id="F1", name="Female 1", tags=("female",)),
|
||||||
|
VoiceManifest(id="F2", name="Female 2", tags=("female",)),
|
||||||
|
VoiceManifest(id="F3", name="Female 3", tags=("female",)),
|
||||||
|
VoiceManifest(id="F4", name="Female 4", tags=("female",)),
|
||||||
|
VoiceManifest(id="F5", name="Female 5", tags=("female",)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
MODEL_REQUIREMENTS: list[ModelManifest] = []
|
MODEL_REQUIREMENTS: list[ModelManifest] = []
|
||||||
|
|||||||
@@ -8,42 +8,23 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from abogen.tts_plugin.capabilities import VoiceLister
|
from abogen.tts_plugin.capabilities import VoiceLister
|
||||||
from abogen.tts_plugin.engine import Engine, EngineSession
|
from abogen.tts_plugin.engine import Engine, EngineSession
|
||||||
from abogen.tts_plugin.errors import EngineError, InvalidInputError
|
from abogen.tts_plugin.errors import EngineError
|
||||||
from abogen.tts_plugin.manifest import VoiceManifest
|
from abogen.tts_plugin.manifest import VoiceManifest
|
||||||
from abogen.tts_plugin.types import (
|
from abogen.tts_plugin.types import (
|
||||||
AudioFormat,
|
AudioFormat,
|
||||||
Duration,
|
Duration,
|
||||||
ParameterValues,
|
|
||||||
SynthesisRequest,
|
SynthesisRequest,
|
||||||
SynthesizedAudio,
|
SynthesizedAudio,
|
||||||
VoiceSelection,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# SuperTonic voice list - source of truth
|
|
||||||
_SUPERTONIC_VOICES = ("M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5")
|
|
||||||
|
|
||||||
# Voice display names mapping
|
|
||||||
_VOICE_DISPLAY_NAMES: dict[str, str] = {
|
|
||||||
"M1": "Male 1",
|
|
||||||
"M2": "Male 2",
|
|
||||||
"M3": "Male 3",
|
|
||||||
"M4": "Male 4",
|
|
||||||
"M5": "Male 5",
|
|
||||||
"F1": "Female 1",
|
|
||||||
"F2": "Female 2",
|
|
||||||
"F3": "Female 3",
|
|
||||||
"F4": "Female 4",
|
|
||||||
"F5": "Female 5",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sample rate for SuperTonic audio
|
# Sample rate for SuperTonic audio
|
||||||
_SUPERTONIC_SAMPLE_RATE = 24000
|
_SUPERTONIC_SAMPLE_RATE = 24000
|
||||||
|
|
||||||
@@ -134,23 +115,11 @@ class SuperTonicEngine:
|
|||||||
self._disposed = True
|
self._disposed = True
|
||||||
|
|
||||||
def listVoices(self, sourceId: str) -> list[VoiceManifest]:
|
def listVoices(self, sourceId: str) -> list[VoiceManifest]:
|
||||||
"""List available SuperTonic voices. Implements VoiceLister capability."""
|
"""List available SuperTonic voices. Implements VoiceLister capability.
|
||||||
|
|
||||||
|
Note: Static voice catalog is declared in plugin manifest.
|
||||||
|
This method is retained for VoiceLister interface compliance.
|
||||||
|
"""
|
||||||
if self._disposed:
|
if self._disposed:
|
||||||
raise EngineError("Engine disposed")
|
raise EngineError("Engine disposed")
|
||||||
return [
|
return []
|
||||||
VoiceManifest(
|
|
||||||
id=voice_id,
|
|
||||||
name=_VOICE_DISPLAY_NAMES.get(voice_id, voice_id),
|
|
||||||
tags=(_get_gender_tag(voice_id),),
|
|
||||||
)
|
|
||||||
for voice_id in _SUPERTONIC_VOICES
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _get_gender_tag(voice_id: str) -> str:
|
|
||||||
"""Extract gender tag from voice ID."""
|
|
||||||
if voice_id.startswith("M"):
|
|
||||||
return "male"
|
|
||||||
elif voice_id.startswith("F"):
|
|
||||||
return "female"
|
|
||||||
return "unknown"
|
|
||||||
|
|||||||
@@ -57,7 +57,15 @@ def _make_mock_engine() -> Any:
|
|||||||
return np.zeros(24000, dtype="float32")
|
return np.zeros(24000, dtype="float32")
|
||||||
return [MockSegment()]
|
return [MockSegment()]
|
||||||
|
|
||||||
return KokoroEngine(MockPipeline(), "a")
|
engine = KokoroEngine(MockPipeline())
|
||||||
|
|
||||||
|
# Override listVoices for testing (real engine reads from manifest)
|
||||||
|
from abogen.tts_plugin.manifest import VoiceManifest
|
||||||
|
engine.listVoices = lambda source_id: [
|
||||||
|
VoiceManifest(id="test_voice_1", name="Test Voice 1", tags=("en",)),
|
||||||
|
VoiceManifest(id="test_voice_2", name="Test Voice 2", tags=("es",)),
|
||||||
|
]
|
||||||
|
return engine
|
||||||
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user