app: add convert_to_wav
This commit is contained in:
parent
17c7400d3e
commit
d3709bd779
22
app.py
22
app.py
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from subprocess import check_call, CalledProcessError
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from flask import request, render_template
|
from flask import request, render_template
|
||||||
|
@ -12,6 +13,21 @@ app = Flask(
|
||||||
os.makedirs("uploads", exist_ok=True)
|
os.makedirs("uploads", exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_to_wav(file_name: str):
|
||||||
|
assert file_name.endswith(".wav")
|
||||||
|
output, extension = file_name.rsplit(".", maxsplit=1)
|
||||||
|
|
||||||
|
assert extension != "wav"
|
||||||
|
|
||||||
|
print(f"{extension=}")
|
||||||
|
command = f"tape2wav {file_name} ${output}.wav"
|
||||||
|
try:
|
||||||
|
check_call(command.split())
|
||||||
|
except CalledProcessError as exc:
|
||||||
|
print(f"tape2wav failed: {exc.output=}\n{exc.stderr=}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def upload_form():
|
def upload_form():
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -40,6 +56,12 @@ def upload_file():
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return f"fail: {exc=}"
|
return f"fail: {exc=}"
|
||||||
|
|
||||||
|
name, extension = file.filename.rsplit(".", maxsplit=1)
|
||||||
|
if extension != "wav":
|
||||||
|
thread = Thread(target=convert_to_wav, args=(file.filename,))
|
||||||
|
thread.start()
|
||||||
|
print(f"thread started for {file.filename=}")
|
||||||
|
|
||||||
return "File uploaded successfully"
|
return "File uploaded successfully"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user