File size: 550 Bytes
2da4544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import APIRouter, UploadFile, File
from services.stt_service import speech_to_text
from models.stt import STTResponse
import os
import uuid

router = APIRouter(prefix="/stt", tags=["Speech To Text"])

@router.post("/", response_model=STTResponse)
async def convert_stt(file: UploadFile = File(...)):
    temp_name = f"audio/temp/{uuid.uuid4()}_{file.filename}"
    
    with open(temp_name, "wb") as f:
        f.write(await file.read())

    text = speech_to_text(temp_name)

    os.remove(temp_name)

    return STTResponse(text=text)