...
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2025-2026 Renato Xavier da Silveira Rosa
|
||||
# Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
||||
# See [LICENSE](./LICENSE) or [BSD-3-Clause-Clear](https://spdx.org/licenses/BSD-3-Clause-Clear.html)
|
||||
"""Backends for the aedocw collection of EPUB->TTS repositories.
|
||||
|
||||
This module defines subclasses of GenericTTSBackend that provide sane
|
||||
default backend command names for the aedocw repositories available on
|
||||
GitHub: epub2tts, epub2tts-edge, epub2tts-chatterbox and epub2tts-kokoro.
|
||||
|
||||
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
|
||||
|
||||
|
||||
class AedocwBackend(GenericTTSBackend):
|
||||
"""Generic aedocw backend wrapper.
|
||||
|
||||
Parameters:
|
||||
repo: repository name (one of the keys in _CMD_MAP)
|
||||
backend_cmd: explicit command/executable to use (overrides repo mapping)
|
||||
language: optional language code
|
||||
voice: optional voice name
|
||||
|
||||
The GenericTTSBackend stores the default command name in self.backend_cmd,
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
class AedocwEpub2TTSEdge(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts-edge."""
|
||||
|
||||
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 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,
|
||||
)
|
||||
|
||||
|
||||
class AedocwKokoro(AedocwBackend):
|
||||
"""Backend configured for github.com/aedocw/epub2tts-kokoro."""
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AedocwBackend",
|
||||
"AedocwEpub2TTS",
|
||||
"AedocwEpub2TTSEdge",
|
||||
"AedocwChatterbox",
|
||||
"AedocwKokoro",
|
||||
]
|
||||
Reference in New Issue
Block a user