59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
import time
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
|
|
from app.config import AppConfig
|
|
from app.speech import router as speech_router
|
|
from app.synthesis import SynthesisEngine
|
|
from app.translit import set_dict_path
|
|
|
|
config = AppConfig.load()
|
|
set_dict_path(config.runtime.translit_dict)
|
|
engine = SynthesisEngine()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
app.state.config = config
|
|
app.state.engine = engine
|
|
engine.use_ssml = config.use_ssml
|
|
engine.ssml_max_chars = config.runtime.ssml_max_chars
|
|
engine.load(
|
|
models_config=config.models,
|
|
sample_rate=config.runtime.sample_rate,
|
|
)
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="Silero TTS", version="0.1.0", lifespan=lifespan)
|
|
app.include_router(speech_router)
|
|
|
|
if config.webui:
|
|
from app.webui import router as webui_router
|
|
app.include_router(webui_router)
|
|
|
|
_SUPPORTED_MODELS = ["UniosTTS"]
|
|
|
|
|
|
@app.get("/v1/models")
|
|
async def models():
|
|
created = int(time.time())
|
|
return {
|
|
"object": "list",
|
|
"data": [
|
|
{"id": m, "object": "model", "created": created, "owned_by": "silero"}
|
|
for m in _SUPPORTED_MODELS
|
|
],
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host=config.runtime.host, port=config.runtime.port)
|