mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 09:45:24 -04:00
2404b00f18
Move every per-route upload byte-limit into src/upload_limits.py as a validated, env-overridable constant via read_byte_limit_env: - Add GALLERY_UPLOAD_MAX_BYTES, GALLERY_TRANSFORM_UPLOAD_MAX_BYTES, MEMORY_IMPORT_MAX_BYTES, PERSONAL_UPLOAD_MAX_BYTES, EMAIL_COMPOSE_UPLOAD_MAX_BYTES, STT_MAX_AUDIO_BYTES, ICS_MAX_BYTES. - Routes import their constant instead of defining it locally: replaces 4 raw int(os.getenv(...)) and removes 3 hardcoded literals. - The 3 previously-hardcoded limits (email compose, STT audio, calendar ICS) are now env-overridable with the same ODYSSEUS_*_MAX_BYTES naming. - Defaults unchanged, so behavior is unchanged unless an env var is set; an invalid value now fails fast with a clear message instead of a bare int() ValueError. - Document all env vars in .env.example and the README. Fixes #3364
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
# routes/stt_routes.py
|
|
"""STT API routes — multi-provider (local Whisper, API endpoint, browser)."""
|
|
|
|
from fastapi import APIRouter, HTTPException, UploadFile, File
|
|
import logging
|
|
|
|
from src.upload_limits import read_upload_limited, STT_MAX_AUDIO_BYTES
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def setup_stt_routes(stt_service):
|
|
"""Setup STT routes with the provided STT service"""
|
|
router = APIRouter(prefix="/api/stt", tags=["stt"])
|
|
|
|
@router.get("/stats")
|
|
async def get_stt_stats():
|
|
"""Get STT service statistics"""
|
|
try:
|
|
return stt_service.get_stats()
|
|
except Exception as e:
|
|
logger.error(f"Failed to get STT stats: {e}")
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
@router.post("/transcribe")
|
|
async def transcribe_audio(file: UploadFile = File(...)):
|
|
"""Transcribe uploaded audio file to text"""
|
|
try:
|
|
if not stt_service.available:
|
|
raise HTTPException(
|
|
status_code=503,
|
|
detail={"message": "STT service not available or set to browser mode"}
|
|
)
|
|
|
|
audio_bytes = await read_upload_limited(file, STT_MAX_AUDIO_BYTES, "Audio file")
|
|
if not audio_bytes:
|
|
raise HTTPException(status_code=400, detail={"message": "Empty audio file"})
|
|
|
|
text = stt_service.transcribe(audio_bytes)
|
|
if text is None:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail={"message": "Transcription failed"}
|
|
)
|
|
|
|
return {"text": text}
|
|
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
logger.error(f"Transcription error: {e}", exc_info=True)
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail={"message": f"Transcription failed: {str(e)}"}
|
|
)
|
|
|
|
return router
|