-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
68 lines (61 loc) · 1.68 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
58
59
60
61
62
63
64
65
66
67
from flask import Flask, request, render_template,Response
from flask_cors import CORS
import utilities
from Gmm import predict
import numpy as np
app = Flask(__name__, template_folder='./template', static_folder='./static')
CORS(app)
cors = CORS(app, resources={
r"/*": {
'origins': '*'
}
})
username= "Unknown"
prediction=[]
words=[]
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict-user', methods=['POST'])
def predict_user():
global prediction
global words
file = request.files['source']
file.save("audio.wav")
Prediction=predict("Voice")
person= np.argmax(Prediction)
print(Prediction)
counter=0
Members=["Dina","Romaisaa","Shaaban"]
for i in range(3):
threshold= 0.7
if person==2:
threshold=1.5
if np.abs(Prediction[person]-Prediction[i])<threshold:
counter+=1
if counter==1:
user_name=Members[person]
words=predict("Voc",Members[person])
wordIndex=np.argmax(words)
if wordIndex!=1:
user_name="Unknown"
else:
user_name="Unknown"
words=[-27,-27,-27,-27]
if max(Prediction)<=-30:
user_name="ERROR"
prediction=Prediction
return [user_name]
@app.route("/plot-data",methods=['POST'])
def plot_data():
global prediction
global words
prediction=np.array(prediction)+35
predict=prediction.tolist()
words=np.array(words)+27
Words=words.tolist()
print(Words)
labels, mfcc,mfcc_coef,time, freq,amp = utilities.dataToDraw()
return[ labels, mfcc,mfcc_coef,time, freq,amp ,predict, Words]
if __name__ == "__main__":
app.run(debug=True, port=5001)