File size: 857 Bytes
64eecf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, UploadFile, File, Form
from ai4bharat.indicstt import IndicSTT
import numpy as np
import wave, io

app = FastAPI()

# Carica il modello UNA VOLTA all'avvio
print("⏳ Caricamento IndicConformer...")
model = IndicSTT("ai4bharat/indic-conformer-600m-multilingual")
print("✅ Modello pronto!")

@app.post("/transcribe")
async def transcribe(audio: UploadFile = File(...), language: str = Form("pa")):
    contents = await audio.read()
    
    # Converti WAV → Float32 normalizzato
    with wave.open(io.BytesIO(contents), 'rb') as f:
        frames = f.readframes(f.getnframes())
        samples = np.frombuffer(frames, dtype=np.int16).astype(np.float32) / 32768.0
    
    # Trascrivi
    result = model.transcribe(samples, language=language)
    
    return {"transcript": result["transcript"], "provider": "indic-conformer"}