Unified aedocw backends
This commit is contained in:
+25
-94
@@ -13,12 +13,6 @@ The vendored packages are run in isolated virtual environments when the
|
||||
corresponding console script is not available in the current environment.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from . import tts_epub2tts as epub2tts_adapter
|
||||
from . import tts_epub2tts_chatterbox as epub2tts_chatterbox_adapter
|
||||
from . import tts_epub2tts_edge as epub2tts_edge_adapter
|
||||
from . import tts_epub2tts_kokoro as epub2tts_kokoro_adapter
|
||||
from .tts_generic import GenericTTSBackend
|
||||
|
||||
|
||||
@@ -35,110 +29,45 @@ class AedocwBackend(GenericTTSBackend):
|
||||
but the vendored adapters may still run the package in their own venv if
|
||||
the console script is not present.
|
||||
"""
|
||||
|
||||
_CMD_MAP = {
|
||||
"epub2tts": "epub2tts",
|
||||
"epub2tts-edge": "epub2tts-edge",
|
||||
"epub2tts-chatterbox": "epub2tts-chatterbox",
|
||||
"epub2tts-kokoro": "epub2tts-kokoro",
|
||||
}
|
||||
|
||||
_RUNNER_MAP = {
|
||||
"epub2tts": epub2tts_adapter.run,
|
||||
"epub2tts-edge": epub2tts_edge_adapter.run,
|
||||
"epub2tts-chatterbox": epub2tts_chatterbox_adapter.run,
|
||||
"epub2tts-kokoro": epub2tts_kokoro_adapter.run,
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
repo: str = "epub2tts",
|
||||
backend_cmd: Optional[str] = None,
|
||||
language: Optional[str] = None,
|
||||
voice: Optional[str] = None,
|
||||
):
|
||||
if backend_cmd is None:
|
||||
backend_cmd = self._CMD_MAP.get(repo, "epub2tts")
|
||||
super().__init__(backend_cmd=backend_cmd, language=language, voice=voice)
|
||||
self.repo = repo
|
||||
|
||||
def run(self, input_source, output_dest):
|
||||
runner = self._RUNNER_MAP.get(self.repo)
|
||||
if runner is None:
|
||||
raise ValueError(f"Unknown repository backend: {self.repo}")
|
||||
|
||||
return runner(
|
||||
input_source,
|
||||
output_dest,
|
||||
language=self.language,
|
||||
voice=self.voice,
|
||||
backend_cmd=self.backend_cmd,
|
||||
)
|
||||
|
||||
FLAGS = {
|
||||
"speaker": "--speaker",
|
||||
"voice": "--speaker",
|
||||
"language": "--language",
|
||||
}
|
||||
INTERMEDIATE_TXT = True
|
||||
|
||||
|
||||
class AedocwEpub2TTS(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
backend_cmd: Optional[str] = None,
|
||||
language: Optional[str] = None,
|
||||
voice: Optional[str] = None,
|
||||
):
|
||||
super().__init__(
|
||||
repo="epub2tts", backend_cmd=backend_cmd, language=language, voice=voice
|
||||
)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class AedocwEpub2TTSEdge(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts-edge."""
|
||||
DEFAULT_SPEAKER = "en-US-AndrewNeural"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
backend_cmd: Optional[str] = None,
|
||||
language: Optional[str] = None,
|
||||
voice: Optional[str] = None,
|
||||
):
|
||||
super().__init__(
|
||||
repo="epub2tts-edge",
|
||||
backend_cmd=backend_cmd,
|
||||
language=language,
|
||||
voice=voice,
|
||||
)
|
||||
|
||||
class TTSEdge(AedocwEpub2TTSEdge):
|
||||
"""Backward-compatible edge backend wrapper."""
|
||||
pass
|
||||
|
||||
|
||||
class AedocwChatterbox(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts-chatterbox."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
backend_cmd: Optional[str] = None,
|
||||
language: Optional[str] = None,
|
||||
voice: Optional[str] = None,
|
||||
):
|
||||
super().__init__(
|
||||
repo="epub2tts-chatterbox",
|
||||
backend_cmd=backend_cmd,
|
||||
language=language,
|
||||
voice=voice,
|
||||
)
|
||||
|
||||
DEFAULT_SAMPLE = "none"
|
||||
|
||||
|
||||
class AedocwKokoro(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts-kokoro."""
|
||||
DEFAULT_SPEAKER = "af_heart"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
backend_cmd: Optional[str] = None,
|
||||
language: Optional[str] = None,
|
||||
voice: Optional[str] = None,
|
||||
):
|
||||
super().__init__(
|
||||
repo="epub2tts-kokoro",
|
||||
backend_cmd=backend_cmd,
|
||||
language=language,
|
||||
voice=voice,
|
||||
)
|
||||
|
||||
|
||||
class Epub2TTS(AedocwBackend):
|
||||
"""Backward-compatible chatterbox backend wrapper."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
__all__ = [
|
||||
@@ -147,4 +76,6 @@ __all__ = [
|
||||
"AedocwEpub2TTSEdge",
|
||||
"AedocwChatterbox",
|
||||
"AedocwKokoro",
|
||||
"TTSEdge",
|
||||
"Epub2TTS",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user