44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from pathlib import Path
|
|
import requests
|
|
import subprocess
|
|
|
|
|
|
def download_from_url(url: str, input_path: Path) -> Path:
|
|
resp = requests.get(url)
|
|
if not resp.ok:
|
|
raise requests.exceptions.HTTPError()
|
|
# TODO think about implementing a naming scheme based on url path
|
|
fname = Path.joinpath(input_path, "inputfile")
|
|
with open(fname, mode="wb") as file:
|
|
file.write(resp.content)
|
|
return fname
|
|
|
|
|
|
def upload_to_oxo(file: Path, url: str = "https://0x0.st", expires: int = 2) -> str:
|
|
resp = requests.post(
|
|
url=url, files={"file": open(file, "rb"), "expires": str(expires)}
|
|
)
|
|
if not resp.ok:
|
|
raise requests.exceptions.HTTPError()
|
|
return str(resp.content)
|
|
|
|
|
|
def convert_to_wav(file: Path, output_path: Path) -> Path:
|
|
fn = Path.joinpath(output_path, "interview.wav")
|
|
subprocess.run(
|
|
[
|
|
"ffmpeg",
|
|
"-i",
|
|
file,
|
|
"-vn",
|
|
"-acodec",
|
|
"pcm_s16le",
|
|
"-ar",
|
|
"16000",
|
|
"-ac",
|
|
"1",
|
|
"-y",
|
|
fn,
|
|
]
|
|
)
|
|
return fn
|