File size: 920 Bytes
5649b92
 
0225b27
 
5649b92
0225b27
5649b92
 
 
 
 
 
 
 
 
0225b27
 
5649b92
0225b27
 
5649b92
0225b27
5649b92
0225b27
 
c2a71d8
5649b92
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
27
28
import uvicorn
from fastapi import FastAPI, File, UploadFile
from func import detect_language_local, transcribe_and_diarize_audio

app = FastAPI(docs_url="/")


@app.post("/transcribe/")
async def transcribe(file: UploadFile = File(...)):
    # Сохраняем загруженный файл временно
    file_location = f"temp_{file.filename}"

    # Читаем содержимое файла и записываем его на диск
    with open(file_location, "wb") as f:
        f.write(await file.read())

    # Детектируем язык
    language = detect_language_local(file_location)

    # Обрабатываем файл (транскрипция и сегментация)
    text, diarized = transcribe_and_diarize_audio(filename=file_location, language=language)

    return {"diarized": diarized}


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