initial commit
This commit is contained in:
49
backend/app/routers/voice.py
Normal file
49
backend/app/routers/voice.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""FluentGerman.ai — Admin voice-to-instruction & voice API router."""
|
||||
|
||||
from fastapi import APIRouter, Depends, UploadFile, File
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.auth import require_admin, get_current_user
|
||||
from app.config import get_settings
|
||||
from app.database import get_db
|
||||
from app.models import User
|
||||
from app.schemas import VoiceConfigOut, VoiceInstructionRequest
|
||||
from app.services.llm_service import summarize_instruction
|
||||
from app.services.voice_service import synthesize, transcribe
|
||||
from fastapi.responses import Response
|
||||
|
||||
router = APIRouter(prefix="/api/voice", tags=["voice"])
|
||||
|
||||
|
||||
@router.get("/config", response_model=VoiceConfigOut)
|
||||
async def voice_config(user: User = Depends(get_current_user)):
|
||||
"""Return current voice mode so frontend knows whether to use browser or API."""
|
||||
return VoiceConfigOut(voice_mode=get_settings().voice_mode)
|
||||
|
||||
|
||||
@router.post("/transcribe")
|
||||
async def transcribe_audio(
|
||||
audio: UploadFile = File(...),
|
||||
user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Transcribe uploaded audio to text (API mode only)."""
|
||||
audio_bytes = await audio.read()
|
||||
text = await transcribe(audio_bytes, filename=audio.filename or "audio.webm")
|
||||
return {"text": text}
|
||||
|
||||
|
||||
@router.post("/synthesize")
|
||||
async def synthesize_text(
|
||||
text: str,
|
||||
user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Convert text to speech audio (API mode only)."""
|
||||
audio_bytes = await synthesize(text)
|
||||
return Response(content=audio_bytes, media_type="audio/mpeg")
|
||||
|
||||
|
||||
@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}
|
||||
Reference in New Issue
Block a user