sampleplayer/sampleplayer.py

27 lines
627 B
Python
Raw Normal View History

2024-05-19 10:13:56 +00:00
from playsound import playsound
2024-05-19 09:18:06 +00:00
from flask import Flask
2024-05-19 10:13:56 +00:00
from flask import render_template
from markupsafe import escape
from os import listdir
from os.path import join
2024-05-19 09:18:06 +00:00
app = Flask(__name__)
2024-05-19 10:13:56 +00:00
samplefiles = listdir('samples')
samples = []
for f in samplefiles:
if '.wav' in f:
samples.append(f.replace('.wav', ''))
2024-05-19 09:18:06 +00:00
@app.route('/')
def hello():
2024-05-19 10:13:56 +00:00
return render_template('index.html', samples=samples)
@app.route('/play/<sample>')
def door(sample):
if sample in samples:
playsound(join('samples', f'{sample}.wav'))
return f'<h1>{escape(sample)}!</h1>'
else:
return 'no such sample'
2024-05-19 09:18:06 +00:00