diff --git a/webui/app.py b/webui/app.py index ff765ce..922a59d 100644 --- a/webui/app.py +++ b/webui/app.py @@ -78,6 +78,23 @@ def _run(cmd: list[str], cwd: Path, env: dict | None = None) -> None: raise gr.Error(f"Command failed ({cmd[0]}):\n{tail}") +def _ensure_wav(path: str) -> str: + """AuK's loader (librosa/soundfile) can't read compressed containers like + .m4a/.mp3 - only demucs's loader handles those. Normalize once, here, at + the point a reference is set, so everything downstream is always wav.""" + if Path(path).suffix.lower() == ".wav": + return path + out_path = WORKDIR / f"converted_{int(time.time() * 1000)}.wav" + result = subprocess.run( + ["ffmpeg", "-nostdin", "-y", "-i", path, "-ar", "44100", "-ac", "1", str(out_path)], + capture_output=True, text=True, timeout=120, + ) + if result.returncode != 0: + tail = "\n".join(result.stderr.strip().splitlines()[-15:]) + raise gr.Error(f"Could not convert '{path}' to wav:\n{tail}") + return str(out_path) + + def _ld_library_path_for_venv(venv_dir: Path) -> str: site_packages = next(venv_dir.glob(".venv/lib/python*/site-packages")) nvidia_dir = site_packages / "nvidia" @@ -123,6 +140,7 @@ def strip_vocals(input_audio: str): def use_as_reference(audio_path: str, history: list): if not audio_path: raise gr.Error("No audio to use yet.") + audio_path = _ensure_wav(audio_path) history = [audio_path] return audio_path, history, _history_label(history)