File size: 702 Bytes
73d4f3c c7fc3b6 73d4f3c c7fc3b6 73d4f3c c7fc3b6 73d4f3c c7fc3b6 73d4f3c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from fastapi import APIRouter, UploadFile, File
from services.tts_service import generate_tts
from services.stt_service import speech_to_text
from fastapi.responses import FileResponse
import uuid
router = APIRouter(prefix="/audio", tags=["Audio"])
@router.post("/tts")
async def tts(text: str):
audio_bytes = await generate_tts(text)
filename = f"tts_{uuid.uuid4()}.wav"
with open(filename, "wb") as f:
f.write(audio_bytes)
return FileResponse(filename, media_type="audio/wav", filename=filename)
@router.post("/stt")
async def stt(file: UploadFile = File(...)):
audio_bytes = await file.read()
text = await speech_to_text(audio_bytes)
return {"text": text}
|