sampleplayer/app.py

32 lines
727 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
2024-05-19 14:29:28 +00:00
from subprocess import check_output
2024-05-19 13:11:57 +00:00
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 14:29:28 +00:00
output = check_output(['amixer', 'sset', 'Master', 'unmute'])
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 14:29:28 +00:00
play_output = check_output(['aplay', '-D', 'hw:0,0', join("samples", f"{sample}.wav")])
2024-05-19 13:11:57 +00:00
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"