forked from server/soundboard
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
from flask import Flask, render_template, request, redirect, url_for
|
|
|
|
path = "/home/pi/sounds"
|
|
|
|
app = Flask(__name__)
|
|
app.jinja_env.trim_blocks = True
|
|
app.jinja_env.lstrip_blocks = True
|
|
|
|
@app.route("/")
|
|
@app.route("/play/<sound>")
|
|
@app.route("/say/", methods=["POST"])
|
|
@app.route("/say/<text>")
|
|
def index(sound=None, text=None, video=None):
|
|
sounds = sorted(os.listdir(path))
|
|
|
|
if sound is not None and sound in sounds:
|
|
subprocess.Popen(["omxplayer", os.path.join(path, sound)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
if text is None:
|
|
text = request.form.get("text")
|
|
|
|
if text is not None:
|
|
voice = request.form.get("voice", default="")
|
|
voice = voice if voice.strip() != "" else "DE"
|
|
speed = request.form.get("speed", default="")
|
|
speed = speed if speed.strip() != "" else "160"
|
|
pitch = request.form.get("pitch", default="")
|
|
pitch = pitch if pitch.strip() != "" else "50"
|
|
|
|
subprocess.Popen(["espeak", "-v", voice, "-s", speed, "-p", pitch, text], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
return redirect("/")
|
|
|
|
video = request.args.get("video")
|
|
|
|
if video is not None:
|
|
url = subprocess.check_output(["youtube-dl", "-g", "-f", "mp4", video]).decode()
|
|
subprocess.Popen(["omxplayer", url.split("\n")[1]])
|
|
subprocess.Popen(["omxplayer", "-b", url.split("\n")[0]])
|
|
|
|
return render_template("index.html", sounds=sounds)
|