- Updated `srt_to_kokoro.py` to provide a CLI entrypoint with argument parsing. - Enhanced error handling and logging for better user feedback. - Introduced a compatibility layer for legacy scripts. - Added configuration handling via `config.toml` for endpoint and API key. - Improved documentation and comments for clarity. Enhance PipelineOrchestrator with in-process transcriber fallback - Implemented `InProcessTranscriber` to handle transcription using multiple strategies. - Added support for `srt_only` flag to return translated SRT without TTS synthesis. - Improved error handling and logging for transcriber initialization. Add installation and usage documentation - Created `INSTALLATION.md` for detailed setup instructions for CPU and GPU environments. - Added `USAGE.md` with practical examples for common use cases and command-line options. - Included a script for automated installation and environment setup. Implement SRT burning utility - Added `burn_srt.py` to facilitate embedding SRT subtitles into video files using ffmpeg. - Provided command-line options for style and codec customization. Update project configuration management - Introduced `config.py` to centralize configuration loading from `config.toml`. - Ensured that environment variables are not read to avoid implicit overrides. Enhance package management with `pyproject.toml` - Added `pyproject.toml` for modern packaging and dependency management. - Defined optional dependencies for CPU and TTS support. Add smoke test fixture for SRT - Created `smoke_test.srt` as a sample subtitle file for testing purposes. Update requirements and setup configurations - Revised `requirements.txt` and `setup.cfg` for better dependency management and clarity. - Included installation instructions for editable mode and local TTS support.
81 lines
1.8 KiB
Python
81 lines
1.8 KiB
Python
"""Central configuration loader.
|
|
|
|
This loader reads configuration exclusively from `config.toml` located in the
|
|
current working directory. It intentionally does NOT read environment
|
|
variables (per project configuration choice) to avoid implicit overrides.
|
|
|
|
Expected TOML structure:
|
|
|
|
[kokoro]
|
|
endpoint = "https://..."
|
|
api_key = "..."
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Defaults (used when keys are missing in TOML)
|
|
_DEFAULTS: dict[str, Any] = {
|
|
"KOKORO_ENDPOINT": None,
|
|
"KOKORO_API_KEY": None,
|
|
}
|
|
|
|
|
|
def _load_toml(path: Path) -> dict[str, Any]:
|
|
try:
|
|
import tomllib
|
|
|
|
with path.open("rb") as fh:
|
|
data = tomllib.load(fh)
|
|
return data if isinstance(data, dict) else {}
|
|
except FileNotFoundError:
|
|
return {}
|
|
except Exception:
|
|
logger.exception("Error leyendo config TOML: %s", path)
|
|
return {}
|
|
|
|
|
|
# Look for ./config.toml only (no environment-based path resolution)
|
|
_config_path = Path.cwd() / "config.toml"
|
|
_TOML: dict[str, Any]
|
|
if _config_path.exists():
|
|
_TOML = _load_toml(_config_path)
|
|
else:
|
|
_TOML = {}
|
|
|
|
|
|
def _toml_get(*keys: str, default: Any = None) -> Any:
|
|
node = _TOML
|
|
for k in keys:
|
|
if not isinstance(node, dict):
|
|
return default
|
|
node = node.get(k, {})
|
|
return node or default
|
|
|
|
|
|
# Public config values read exclusively from TOML (TOML > defaults)
|
|
KOKORO_ENDPOINT = (
|
|
_toml_get(
|
|
"kokoro",
|
|
"endpoint",
|
|
default=_DEFAULTS["KOKORO_ENDPOINT"],
|
|
)
|
|
or None
|
|
)
|
|
KOKORO_API_KEY = (
|
|
_toml_get(
|
|
"kokoro",
|
|
"api_key",
|
|
default=_DEFAULTS["KOKORO_API_KEY"],
|
|
)
|
|
or None
|
|
)
|
|
|
|
|
|
__all__ = ["KOKORO_ENDPOINT", "KOKORO_API_KEY"]
|