D1: LUFS EBU R128 + true peak sau render (app/core/loudness.py), API /plugins/render tra them lufs/true_peak_db, test 4 cases

This commit is contained in:
2026-08-22 21:50:29 +07:00
parent 2a5e2af04a
commit fe82b19557
3 changed files with 149 additions and 1 deletions
+14 -1
View File
@@ -1181,7 +1181,20 @@ def render_project(
output_path = os.path.join(settings.PROCESSED_DIR, safe_name)
try:
result_path = engine.render_project(req.project_json, output_path)
return {"url": f"/static/audio/processed/{os.path.basename(result_path)}", "path": result_path}
# EBU R128 loudness + true peak (D1) — trả kèm response để mastering
# panel hiển thị LUFS/dBTP ngay sau export mà không cần đọc lại file.
data, _sr = sf.read(result_path, dtype="float32", always_2d=True)
audio = data.T
from app.core import loudness
resp = {
"url": f"/static/audio/processed/{os.path.basename(result_path)}",
"path": result_path,
}
_lufs = loudness.integrated_lufs(audio, _sr)
_tp = loudness.true_peak_db(audio, _sr)
resp["lufs"] = round(_lufs, 2) if np.isfinite(_lufs) else None
resp["true_peak_db"] = round(_tp, 2) if np.isfinite(_tp) else None
return resp
except Exception as e:
raise HTTPException(status_code=500, detail=f"Render failed: {str(e)}")