implemented 15,12,18 didn't check 18
This commit is contained in:
@ -11,7 +11,7 @@ from fastapi import APIRouter, HTTPException, Query, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from pydantic import BaseModel
|
||||
|
||||
from services.audio_cleaner import clean_audio, detect_silence_ranges, is_deepfilter_available
|
||||
from services.audio_cleaner import clean_audio, detect_silence_ranges, is_deepfilter_available, normalize_audio
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
@ -164,3 +164,30 @@ async def get_waveform_audio(request: Request, path: str = Query(...)):
|
||||
)
|
||||
_waveform_cache[cache_key] = str(out_wav)
|
||||
return FileResponse(str(out_wav), media_type="audio/wav")
|
||||
|
||||
|
||||
class NormalizeRequest(BaseModel):
|
||||
input_path: str
|
||||
output_path: Optional[str] = None
|
||||
target_lufs: float = -14.0
|
||||
|
||||
|
||||
@router.post("/audio/normalize")
|
||||
async def normalize_audio_endpoint(req: NormalizeRequest):
|
||||
"""Normalize audio loudness to a target LUFS level using FFmpeg loudnorm."""
|
||||
if req.target_lufs < -70 or req.target_lufs > 0:
|
||||
raise HTTPException(status_code=400, detail="target_lufs must be between -70 and 0")
|
||||
try:
|
||||
output = normalize_audio(
|
||||
req.input_path,
|
||||
req.output_path or "",
|
||||
target_lufs=req.target_lufs,
|
||||
)
|
||||
return {
|
||||
"status": "ok",
|
||||
"output_path": output,
|
||||
"target_lufs": req.target_lufs,
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Audio normalization failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user