from fastapi import APIRouter, Depends, HTTPException, Query from fastapi.responses import Response from auth import get_current_user from models import User from services.tts_service import TtsServiceError, tts_service router = APIRouter(prefix="/api", tags=["tts"]) @router.get("/tts/speak") def speak_word( text: str = Query(..., min_length=1, max_length=200), current_user: User = Depends(get_current_user), ): try: audio_bytes, content_type = tts_service.synthesize(text) except TtsServiceError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc return Response( content=audio_bytes, media_type=content_type, headers={"Cache-Control": "private, max-age=86400"}, )