-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (49 loc) · 1.86 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
from flask import Flask, render_template
from flask_socketio import SocketIO, join_room, leave_room
import emotions
import voicetest
app = Flask(__name__)
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
socketio = SocketIO(app)
alldata = {}
@app.route('/')
def sessions():
return render_template('session.html')
def messageReceived(methods=['GET', 'POST']):
print('message was received!!!')
@socketio.on('message')
def handle_message_event(json, methods=['GET', 'POST']):
print('received my event: ' + str(json))
socketio.emit('my response', json, callback=messageReceived)
@socketio.on('join')
def on_join(data):
username = data['username']
room = data['room']
join_room(room)
socketio.send({ "type": "Connection:", "content": username + ' has entered the room ' + room}, room=room)
@socketio.on('leave')
def on_leave(data):
username = data['username']
room = data['room']
leave_room(room)
socketio.send(username + ' has left the room.', room=room)
@socketio.on('photo')
def handle_photo_event(data, methods=['GET', 'POST']):
print("received photo")
# print(photo)
# print(data)
emotion = emotions.tell_emotion(data['photo'])
# photo is based64 blob, decode and do emotion detection
# do emotion detection
socketio.emit('photo result', {"username": data['username'], "emotion": emotion})
@socketio.on('audio')
def handle_audio_event(data, methods=['GET', 'POST']):
print("received audio from ", data['username'])
print(data['audio'])
text = voicetest.audiototext(data['audio'])
# TODO: do audio processing here
#newAudio = data["audio"] # this should be computer generated voice
#text = "David sucks ass" # this should be NLP text
socketio.emit('audio result', {"username": data['username'], "audio": data['audio'], "text": text })
if __name__ == '__main__':
socketio.run(app, debug=True)