-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (35 loc) · 1.11 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
from flask import Flask
from flask import render_template
from flask import send_from_directory
from flask import request
from flask_cors import CORS
from setup import app, APP_PATH, DS, DV
import uuid, os
CORS(app, resources={r"/api/*": {"origins": "*"}})
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api/listen', methods=['POST'])
def listen():
f = request.files['audio']
a = request.form['account']
# Create folder if it doesn't exist
folder = APP_PATH + DS + 'storage' + DS
if not os.path.exists(folder):
os.makedirs(folder)
# Save wave in folder
file_path = folder + str(uuid.uuid4()) + '.wav'
f.save(file_path)
# Attempt to match recording
dejavu = DV()
song = dejavu.listen(file_path)
print(song)
# NOTE: When matching device, check that IPs match ? Should be in same network right ?
# Cleanup. Delete file
# os.remove(file_path)
return song
@app.route('/listen.js')
def get_script():
return send_from_directory(APP_PATH + DS + 'dv', 'listen.min.js')
if __name__ == '__main__':
app.run(port=80)