File size: 697 Bytes
a4ff920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI, UploadFile
from vosk_handler import VoskTranscriber
import io

app = FastAPI()
transcriber = VoskTranscriber()

@app.post("/transcribe/")
async def transcribe_audio(audio_file: UploadFile):
    try:
        # Read file content into memory
        content = await audio_file.read()
        # Create in-memory file-like object
        audio_data = io.BytesIO(content)
        # Process the audio
        result = transcriber.transcribe_audio(audio_data)
        return result
    except Exception as e:
        return {"success": False, "error": str(e)}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)