FluentQ / app /main.py
tommytracx's picture
Upload 4 files
42c727a verified
raw
history blame
1 kB
from fastapi import FastAPI, UploadFile, File, Request
from fastapi.middleware.cors import CORSMiddleware
from app.agent import process_text
from app.speech_to_text import transcribe_audio
from app.text_to_speech import synthesize_speech
from fastapi.responses import StreamingResponse, JSONResponse
import io
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/transcribe")
async def transcribe(file: UploadFile = File(...)):
audio_bytes = await file.read()
text = transcribe_audio(audio_bytes)
return {"transcription": text}
@app.post("/query")
async def query_agent(request: Request):
data = await request.json()
input_text = data.get("input_text", "")
response = process_text(input_text)
return {"response": response}
@app.get("/speak")
async def speak(text: str):
audio = synthesize_speech(text)
return StreamingResponse(io.BytesIO(audio), media_type="audio/wav")