-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsawaaljawaab.py
120 lines (103 loc) · 3.49 KB
/
sawaaljawaab.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import unicode_literals
from flask import Flask, request, jsonify, current_app
from functools import wraps
import sys
import os
import json
from flask.ext.cors import CORS
from scipy.io.wavfile import read as wavread
import inspect
import sys
from src import tablaAnalysis as anal
PULSEP = 0.5
TAAL_ID = "teen" # 1 for teental, 2 for ektaal, 3 for rupak taal, 4 for jhap taal
app = Flask(__name__)
CORS(app)
TablaStrokesPath = json.load(open('../dataset/filelist.json', 'r'))
clickStrokes = {'hiClick': '../dataset/hiclick.wav', 'lowClick': '../dataset/loclick.wav'}
@app.route('/')
def index():
return "thing"
def support_jsonp(f):
"""Wraps JSONified output for JSONP"""
@wraps(f)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
content = str(callback) + '(' + str(f(*args, **kwargs)) + ')'
return current_app.response_class(content, mimetype='application/javascript')
else:
return f(*args, **kwargs)
return decorated_function
@app.route('/get_tabla_sounds', methods=['GET', 'POST'])
@support_jsonp
def get_tabla_sounds():
"""
http://127.0.0.1:5000/get_tabla_sounds
simple! and you get the json data :)
"""
#read a wav sound
output = {}
for stroke in TablaStrokesPath.keys():
fs, data = wavread(TablaStrokesPath[stroke])
output[stroke] = data.tolist()
return jsonify(**output)
@app.route('/get_click_sounds', methods=['GET', 'POST'])
@support_jsonp
def get_click_sounds():
"""
http://127.0.0.1:5000/get_tabla_sounds
simple! and you get the json data :)
"""
#read a wav sound
output = {}
for stroke in clickStrokes.keys():
fs, data = wavread(clickStrokes[stroke])
output[stroke] = data.tolist()
return jsonify(**output)
@app.route('/get_tala_info', methods=['GET', 'POST'])
@support_jsonp
def get_tala_info():
"""
http://127.0.0.1:5000/get_tala_info
simple! and you get the json data :)
"""
TalaInfoFULL = json.load(open('../dataset/exampleOutput.json', 'r'))
return jsonify(**TalaInfoFULL)
@app.route('/set_tempo', methods=['GET', 'POST'])
@support_jsonp
def set_tempo():
"""
"""
global PULSEP
if request.method == 'POST':
PULSEP = request.get_json()['tempo']
#tempo = float(request.args.get('tempo'))
return jsonify(**{'status': True, 'tempo': PULSEP})
@app.route('/set_taal', methods=['GET', 'POST'])
@support_jsonp
def set_taal():
"""
"""
global TAAL_ID
if request.method == 'POST':
TAAL_ID = request.get_json()['taal']
return jsonify(**{'status': True, 'taal': TAAL_ID})
@app.route('/upload_audio', methods=['GET', 'POST'])
@support_jsonp
def upload_audio():
"""
Example: http://127.0.0.1:5000/upload_audio?audio=[1,2,3]
you have to see how to send json object, we can parse that. We might need that for passing audio arrays
"""
if request.method == 'POST':
blob = request.files['data']
file_out = 'temp.wav'
blob.save(file_out)
audio = anal.ess.MonoLoader(filename=file_out.encode('utf-8'))()
featFull, strokeSeq, strokeTime, strokeAmp, opulsePer = anal.getJawaabLive(audio, PULSEP, iTaal = TAAL_ID)
output = {'strokeTime': strokeTime.tolist(), 'strokeAmp': strokeAmp.tolist(), 'strokeList': strokeSeq}
return jsonify(**output)
if __name__ == '__main__':
app.config['DEBUG'] = True
app.run(host= '0.0.0.0', debug = True)