2019-06-08 09:17:21 +00:00
|
|
|
from flask import Flask, request
|
|
|
|
|
import os
|
|
|
|
|
import simpleaudio as sa
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
p = None
|
2019-06-10 11:54:58 +00:00
|
|
|
w = sa.WaveObject.from_wave_file("./rave.wav")
|
2019-06-08 09:17:21 +00:00
|
|
|
playing = False
|
|
|
|
|
|
|
|
|
|
@app.route('/play')
|
|
|
|
|
def index():
|
2019-06-10 11:54:58 +00:00
|
|
|
global playing, p, w
|
2019-06-08 09:17:21 +00:00
|
|
|
if playing:
|
2019-06-27 17:55:59 +00:00
|
|
|
return str(406)
|
2019-06-10 11:54:58 +00:00
|
|
|
else:
|
|
|
|
|
playing = True
|
|
|
|
|
p = w.play()
|
2019-06-27 17:55:59 +00:00
|
|
|
return str(200)
|
2019-06-08 09:17:21 +00:00
|
|
|
|
|
|
|
|
@app.route('/stop')
|
|
|
|
|
def test():
|
2019-06-10 11:54:58 +00:00
|
|
|
global playing, p
|
2019-06-08 09:17:21 +00:00
|
|
|
if playing:
|
2019-06-10 11:54:58 +00:00
|
|
|
playing = False
|
|
|
|
|
p.stop()
|
2019-06-27 17:55:59 +00:00
|
|
|
return str(200)
|
2019-06-15 17:19:31 +00:00
|
|
|
else:
|
2019-06-27 17:55:59 +00:00
|
|
|
return str(406)
|
2019-06-08 09:17:21 +00:00
|
|
|
|
2019-06-10 11:54:58 +00:00
|
|
|
|
|
|
|
|
port = int(os.environ.get('PORT', 81))
|
|
|
|
|
app.run(host='0.0.0.0', port=port)
|
2019-06-08 09:17:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|