-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
41 lines (34 loc) · 1011 Bytes
/
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
from flask import Flask, request, jsonify
from pydub import AudioSegment
from inference import result
import config
def revise(sentence):
words = sentence.split()
result = []
for word in words:
tmp = ''
for t in word:
if not tmp:
tmp += t
elif tmp[-1]!= t:
tmp += t
result.append(tmp)
return ' '.join(result)
app = Flask(__name__)
@app.route('/')
def start():
return 'start'
@app.route('/upload',methods=['POST'])
def inference():
if request.method == "POST":
audiofile = request.files["file"]
filename = audiofile.filename
track = AudioSegment.from_file(audiofile, format= 'm4a')
file_handle = track.export('audio.wav', format='wav')
response = {}
data = revise(result()[0])
response['text'] = data
print(data)
return jsonify(response)
if __name__ == '__main__':
app.run(host=config.IP_CONFIG['host'],port='5000')