Files
teams-whisper/app/audio.py
T

21 lines
1.0 KiB
Python

"""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]
# 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)
# Surface the tail of ffmpeg's error output.
if r.returncode: raise RuntimeError(r.stderr[-500:])
# Store the duration probed from the output file.
db.upsert_recording(name, duration_s=db.duration(dst))
return dst