mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
refactor: move backend implementations to tts_backends package
Moved SupertonicPipeline from abogen/tts_supertonic.py to abogen/tts_backends/supertonic.py and load_numpy_kpipeline from abogen/utils.py to abogen/tts_backends/kokoro.py. Git correctly detects the Supertonic file as a rename (R), preserving full commit history. - New package: abogen/tts_backends/ - __init__.py (package marker) - supertonic.py (SupertonicPipeline, moved from tts_supertonic.py) - kokoro.py (load_numpy_kpipeline, moved from utils.py) - abogen/utils.py: re-exports load_numpy_kpipeline for backward compat - All imports updated to new canonical paths
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
def load_numpy_kpipeline():
|
||||
import numpy as np
|
||||
from kokoro import KPipeline # type: ignore[import-not-found]
|
||||
|
||||
return np, KPipeline
|
||||
+2
-7
@@ -529,13 +529,6 @@ def prevent_sleep_end():
|
||||
_sleep_procs[system] = None
|
||||
|
||||
|
||||
def load_numpy_kpipeline():
|
||||
import numpy as np
|
||||
from kokoro import KPipeline # type: ignore[import-not-found]
|
||||
|
||||
return np, KPipeline
|
||||
|
||||
|
||||
class LoadPipelineThread(Thread):
|
||||
def __init__(self, callback):
|
||||
super().__init__()
|
||||
@@ -543,6 +536,8 @@ class LoadPipelineThread(Thread):
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
from abogen.tts_backends.kokoro import load_numpy_kpipeline
|
||||
|
||||
np_module, kpipeline_class = load_numpy_kpipeline()
|
||||
self.callback(np_module, kpipeline_class, None)
|
||||
except Exception as e:
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
from typing import Any, Dict, Iterable, List, Tuple
|
||||
|
||||
from abogen.constants import VOICES_INTERNAL
|
||||
from abogen.tts_supertonic import DEFAULT_SUPERTONIC_VOICES
|
||||
from abogen.tts_backends.supertonic import DEFAULT_SUPERTONIC_VOICES
|
||||
from abogen.utils import get_user_config_path
|
||||
|
||||
|
||||
|
||||
@@ -39,15 +39,15 @@ from abogen.utils import (
|
||||
get_user_cache_path,
|
||||
get_user_output_path,
|
||||
load_config,
|
||||
load_numpy_kpipeline,
|
||||
)
|
||||
from abogen.tts_backends.kokoro import load_numpy_kpipeline
|
||||
from abogen.tts_backend import TTSBackend
|
||||
from abogen.voice_cache import ensure_voice_assets
|
||||
from abogen.voice_formulas import extract_voice_ids, get_new_voice
|
||||
from abogen.voice_profiles import load_profiles, normalize_profile_entry
|
||||
from abogen.pronunciation_store import increment_usage
|
||||
from abogen.llm_client import LLMClientError
|
||||
from abogen.tts_supertonic import DEFAULT_SUPERTONIC_VOICES, SupertonicPipeline
|
||||
from abogen.tts_backends.supertonic import DEFAULT_SUPERTONIC_VOICES, SupertonicPipeline
|
||||
|
||||
from .service import Job, JobStatus
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from abogen.normalization_settings import build_apostrophe_config
|
||||
from abogen.text_extractor import extract_from_path
|
||||
from abogen.voice_cache import ensure_voice_assets
|
||||
from abogen.webui.conversion_runner import SAMPLE_RATE, SPLIT_PATTERN, _select_device, _to_float32, _resolve_voice, _spec_to_voice_ids
|
||||
from abogen.utils import load_numpy_kpipeline
|
||||
from abogen.tts_backends.kokoro import load_numpy_kpipeline
|
||||
|
||||
|
||||
_MARKER_RE = re.compile(re.escape(MARKER_PREFIX) + r"(?P<code>[A-Z0-9_]+)" + re.escape(MARKER_SUFFIX))
|
||||
|
||||
@@ -78,7 +78,7 @@ def get_preview_pipeline(language: str, device: str) -> Any:
|
||||
pipeline = _preview_pipelines.get(key)
|
||||
if pipeline is not None:
|
||||
return pipeline
|
||||
from abogen.utils import load_numpy_kpipeline
|
||||
from abogen.tts_backends.kokoro import load_numpy_kpipeline
|
||||
|
||||
_, KPipeline = load_numpy_kpipeline()
|
||||
pipeline = KPipeline(lang_code=language, repo_id="hexgrad/Kokoro-82M", device=device)
|
||||
@@ -137,7 +137,7 @@ def generate_preview_audio(
|
||||
normalized_text = source_text
|
||||
|
||||
if provider == "supertonic":
|
||||
from abogen.tts_supertonic import SupertonicPipeline
|
||||
from abogen.tts_backends.supertonic import SupertonicPipeline
|
||||
|
||||
pipeline = SupertonicPipeline(sample_rate=SAMPLE_RATE, auto_download=True, total_steps=supertonic_total_steps)
|
||||
segments = pipeline(
|
||||
|
||||
@@ -20,7 +20,7 @@ from abogen.constants import (
|
||||
VOICES_INTERNAL,
|
||||
)
|
||||
from abogen.speaker_configs import list_configs
|
||||
from abogen.utils import load_numpy_kpipeline
|
||||
from abogen.tts_backends.kokoro import load_numpy_kpipeline
|
||||
from abogen.webui.conversion_runner import _select_device, _to_float32, SAMPLE_RATE, SPLIT_PATTERN
|
||||
|
||||
_preview_pipeline_lock = threading.RLock()
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_preview_applies_manual_override_before_normalization(monkeypatch):
|
||||
|
||||
monkeypatch.setitem(
|
||||
__import__("sys").modules,
|
||||
"abogen.tts_supertonic",
|
||||
"abogen.tts_backends.supertonic",
|
||||
type("M", (), {"SupertonicPipeline": DummyPipeline}),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import numpy as np
|
||||
|
||||
from abogen.tts_supertonic import SupertonicPipeline
|
||||
from abogen.tts_backends.supertonic import SupertonicPipeline
|
||||
|
||||
|
||||
class _DummyTTS:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abogen.webui.conversion_runner import _resolve_voice, _supertonic_voice_from_spec
|
||||
from abogen.tts_supertonic import DEFAULT_SUPERTONIC_VOICES
|
||||
from abogen.tts_backends.supertonic import DEFAULT_SUPERTONIC_VOICES
|
||||
|
||||
|
||||
def test_resolve_voice_formula_without_pipeline_does_not_crash() -> None:
|
||||
|
||||
Reference in New Issue
Block a user