sampleplayer/app.py

29 lines
613 B
Python
Raw Normal View History

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