55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import json
|
|
from pathlib import Path
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class ModelConfig:
|
|
file: str
|
|
languages: list[str] = field(default_factory=list)
|
|
|
|
|
|
@dataclass
|
|
class RuntimeConfig:
|
|
sample_rate: int = 24000
|
|
ffmpeg_path: str = "ffmpeg"
|
|
translit_dict: str = "translit_dict.json"
|
|
port: int = 5215
|
|
host: str = "0.0.0.0"
|
|
ssml_max_chars: int = 500
|
|
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
models: list[ModelConfig] = field(default_factory=list)
|
|
model_voices: dict[str, dict[str, str]] = field(default_factory=dict)
|
|
runtime: RuntimeConfig = field(default_factory=RuntimeConfig)
|
|
webui: bool = False
|
|
use_ssml: bool = True
|
|
|
|
@classmethod
|
|
def load(cls, path: str | Path = "config.json") -> "AppConfig":
|
|
with open(path, encoding="utf-8") as f:
|
|
raw = json.load(f)
|
|
models = [
|
|
ModelConfig(file=m["file"], languages=m.get("languages", []))
|
|
for m in raw.get("models", [])
|
|
]
|
|
model_voices = raw.get("model_voices", {})
|
|
rt = raw.get("runtime", {})
|
|
runtime = RuntimeConfig(
|
|
sample_rate=rt.get("sample_rate", 24000),
|
|
ffmpeg_path=rt.get("ffmpeg_path", "ffmpeg"),
|
|
translit_dict=rt.get("translit_dict", "translit_dict.json"),
|
|
port=int(rt.get("port", 5215)),
|
|
host=rt.get("host", "0.0.0.0"),
|
|
ssml_max_chars=int(rt.get("ssml_max_chars", 500)),
|
|
)
|
|
return cls(
|
|
models=models,
|
|
model_voices=model_voices,
|
|
runtime=runtime,
|
|
webui=raw.get("webui", False),
|
|
use_ssml=raw.get("use_ssml", True),
|
|
)
|