Interaction-without-Interac.../client/main.py

40 lines
597 B
Python
Raw Normal View History

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")
playing = False
@app.route('/play')
def index():
2019-06-10 11:54:58 +00:00
global playing, p, w
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)
@app.route('/stop')
def test():
2019-06-10 11:54:58 +00:00
global playing, p
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-10 11:54:58 +00:00
port = int(os.environ.get('PORT', 81))
app.run(host='0.0.0.0', port=port)