-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (55 loc) · 1.84 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
68
69
70
71
72
73
74
75
76
77
78
from flask import Flask, request
from flask_classy import FlaskView
from model import Conversation
from model import session
from setting import PLUGINS
USE_IBM = False
import base64
import dateutil.parser
import julius.recognition as recognition
import threading
import os
import sys
from conv_endian import *
if USE_IBM:
import ibm
recognizer = ibm
else:
import julius.recognition as julius
recognizer = julius
app = Flask(__name__)
class IndexView(FlaskView):
def index(self):
return "hello world"
IndexView.register(app)
class ApiView(FlaskView):
def post(self):
voice = request.json['data']
speaked_at = request.json['speaked_at']
print('*** request.json ***', file=sys.stderr)
# print(request.json, file=sys.stderr)
print('*** ************ ***', file=sys.stderr)
voice = base64.b64decode(voice)
voice = conv_endian(voice)
speaked_at = dateutil.parser.parse(speaked_at)
print('**** speaked_at ****', file=sys.stderr)
print(speaked_at, file=sys.stderr)
print('*** ************ ***', file=sys.stderr)
# voiceを認識
voice = recognizer.recognize(voice)
print('****** voice *******', file=sys.stderr)
print(voice, file=sys.stderr)
print('*** ************ ***', file=sys.stderr)
conversation = Conversation(content=voice, speaked_at=speaked_at)
session.add(conversation)
session.commit()
return "ok"
ApiView.register(app)
print('--- LOAD PLUGINS ---', file=sys.stderr)
for plugin in PLUGINS:
print(f'load {plugin.plugin_name}', file=sys.stderr)
plugin.register(app)
print('--------------------', file=sys.stderr)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', threaded=False, ssl_context=(
'cert/server.crt', 'cert/server.key'))