-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (47 loc) · 1.35 KB
/
app.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from fastapi import FastAPI, File, UploadFile
from datetime import datetime
from conversions import convert_it
import asyncio
app = FastAPI()
from fastapi.middleware.cors import CORSMiddleware
origins = [
"http://localhost",
"http://localhost:8080",
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
#asr_model = EncoderASR.from_hparams(source="speechbrain/asr-wav2vec2-librispeech", savedir="pretrained_models/asr-wav2vec2-librispeech")
FILE_STORAGE = "../../files"
@app.post("/files/")
async def create_file(lang: str, file: bytes = File()):
'''
Just for wav formats
'''
#print(type(file))
try:
file_name = f"{FILE_STORAGE}/{datetime.now().timestamp()}.wav"
with open(file_name, 'wb+') as f:
f.write(file)
asr_model = convert_it(lang)
text = asr_model.transcribe_file(file_name)
ok = True
except:
ok = False
text = 'failed'
import traceback; traceback.print_exc();
#if ok:
# text = convert.delay(f'./{file_name}')
return {"file_size": len(file), 'ok' : ok, 'text':text}
"""
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile):
#print
contents = await file.read()
return {"content": contents}
"""