Spaces:
Running
Running
| from typing import Annotated | |
| from fastapi import APIRouter, Depends, HTTPException, Request, status | |
| from fastapi.responses import Response | |
| from app.models.speech import SynthesizeRequest | |
| from app.security.jwt_auth import verify_jwt | |
| router = APIRouter() | |
| async def synthesize_endpoint( | |
| request: Request, | |
| payload: SynthesizeRequest, | |
| _: Annotated[dict, Depends(verify_jwt)], | |
| ) -> Response: | |
| tts_client = request.app.state.tts_client | |
| if not tts_client.is_configured: | |
| raise HTTPException( | |
| status_code=status.HTTP_503_SERVICE_UNAVAILABLE, | |
| detail="TTS service is not configured.", | |
| ) | |
| audio_bytes = await tts_client.synthesize( | |
| payload.text.strip(), | |
| voice=payload.voice.strip().lower(), | |
| ) | |
| return Response(content=audio_bytes, media_type="audio/wav") | |