sampleplayer/app.py
Sophie Schiller 37d9e3780f gunicorn?
2024-05-19 15:11:57 +02:00

28 lines
613 B
Python

from os import listdir
from os.path import join
from flask import Flask, render_template
from markupsafe import escape
from playsound import playsound
app = Flask(__name__)
samplefiles = listdir("samples")
samples = []
for f in samplefiles:
if ".wav" in f:
samples.append(f.replace(".wav", ""))
@app.route("/")
def hello():
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"