Some checks failed
Deploy FluentGerman.ai / deploy (push) Failing after 27s
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""FluentGerman.ai — Admin voice-to-instruction & voice API router."""
|
|
|
|
from fastapi import APIRouter, Depends, UploadFile, File, HTTPException
|
|
import logging
|
|
|
|
# ... imports ...
|
|
|
|
logger = logging.getLogger("fluentgerman.voice")
|
|
|
|
# ...
|
|
|
|
@router.post("/transcribe")
|
|
async def transcribe_audio(
|
|
audio: UploadFile = File(...),
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
"""Transcribe uploaded audio to text (API mode only)."""
|
|
try:
|
|
audio_bytes = await audio.read()
|
|
text = await transcribe(audio_bytes, filename=audio.filename or "audio.webm")
|
|
return {"text": text}
|
|
except Exception as e:
|
|
logger.error(f"Transcription failed: {str(e)}", exc_info=True)
|
|
raise HTTPException(status_code=500, detail=f"Transcription failed: {str(e)}")
|
|
|
|
|
|
@router.post("/synthesize")
|
|
async def synthesize_text(
|
|
text: str,
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
"""Convert text to speech audio (API mode only)."""
|
|
try:
|
|
audio_bytes = await synthesize(text)
|
|
return Response(content=audio_bytes, media_type="audio/mpeg")
|
|
except Exception as e:
|
|
logger.error(f"Synthesis failed: {str(e)}", exc_info=True)
|
|
raise HTTPException(status_code=500, detail=f"Synthesis failed: {str(e)}")
|
|
|
|
|
|
@router.post("/generate-instruction", dependencies=[Depends(require_admin)])
|
|
async def generate_instruction(body: VoiceInstructionRequest):
|
|
"""Admin: takes raw transcript and returns a structured instruction via LLM."""
|
|
structured = await summarize_instruction(body.raw_text)
|
|
return {"instruction": structured}
|