# FlowerCore biblical-tts — eSpeak-NG-backed TTS for Ancient Greek (grc) and
# Hebrew (he). Wraps the espeak-ng binary in a small FastAPI app exposing
# /tts (returns WAV) and /timings (returns word timings via espeak's
# --pho output). Same shape as fc-speech-align so AiStation can talk to
# both with one HTTP client pattern.
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1

# espeak-ng has built-in support for grc (Ancient Greek) and he (Hebrew).
# libsndfile1 is for the wav post-processing step.
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        espeak-ng \
        libsndfile1 \
        ca-certificates \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py /app/

RUN useradd --create-home --shell /usr/sbin/nologin --uid 1654 tts
USER 1654

EXPOSE 10402
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
    CMD python -c "import urllib.request,sys; urllib.request.urlopen('http://127.0.0.1:10402/health',timeout=3); sys.exit(0)" || exit 1

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "10402", "--workers", "1"]
