Apply ruff lint and rename cryptic identifiers to readable names
This commit is contained in:
+35
-10
@@ -1,20 +1,45 @@
|
||||
"""Cheap non-AI audio cleanup: mono 16k, highpass, loudnorm -> out/<name>/audio.opus."""
|
||||
|
||||
import subprocess
|
||||
|
||||
import db
|
||||
|
||||
|
||||
# Convert the meeting's audio track to 16 kHz mono Opus (small, speech-optimised).
|
||||
def run(name):
|
||||
src = db.media(name)[0]
|
||||
source_path = db.media(name)[0]
|
||||
# No audio track: nothing to convert.
|
||||
if src is None: raise FileNotFoundError(f"no audio source for {name}")
|
||||
dst = db.out_dir(name) / "audio.opus"
|
||||
r = subprocess.run(["ffmpeg", "-y", "-v", "error", "-i", str(src), "-vn", "-ac", "1", "-ar", "16000",
|
||||
# highpass 80 Hz removes rumble; loudnorm evens out volume (EBU R128: -18 LUFS, -2 dBTP peak, LRA 11); 24 kbps Opus.
|
||||
"-af", "highpass=f=80,loudnorm=I=-18:TP=-2:LRA=11", "-c:a", "libopus", "-b:a", "24k", str(dst)],
|
||||
capture_output=True, text=True)
|
||||
if source_path is None:
|
||||
raise FileNotFoundError(f"no audio source for {name}")
|
||||
output_path = db.out_dir(name) / "audio.opus"
|
||||
result = subprocess.run(
|
||||
[
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(source_path),
|
||||
"-vn",
|
||||
"-ac",
|
||||
"1",
|
||||
"-ar",
|
||||
"16000",
|
||||
# highpass 80 Hz removes rumble; loudnorm evens out volume (EBU R128: -18 LUFS, -2 dBTP peak, LRA 11); 24 kbps Opus.
|
||||
"-af",
|
||||
"highpass=f=80,loudnorm=I=-18:TP=-2:LRA=11",
|
||||
"-c:a",
|
||||
"libopus",
|
||||
"-b:a",
|
||||
"24k",
|
||||
str(output_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
# Surface the tail of ffmpeg's error output.
|
||||
if r.returncode: raise RuntimeError(r.stderr[-500:])
|
||||
if result.returncode:
|
||||
raise RuntimeError(result.stderr[-500:])
|
||||
# Store the duration probed from the output file.
|
||||
db.upsert_recording(name, duration_s=db.duration(dst))
|
||||
return dst
|
||||
db.upsert_recording(name, duration_s=db.duration(output_path))
|
||||
return output_path
|
||||
|
||||
Reference in New Issue
Block a user