Fix AuK editor failing on non-wav uploads (e.g. m4a)

AuK's loader (librosa/soundfile) can't read compressed containers like
m4a/mp3 at all - only demucs's loader handles those. Gradio keeps
uploads in their original format, so any edit attempted directly on an
uploaded m4a failed with "Format not recognised."

Normalize to wav via ffmpeg at the single point a reference is set
(use_as_reference), so both AuK and MOSS-TTS downstream always see wav
regardless of what was uploaded.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1oQ4h4WE4R9KRvMQLr5Ey
This commit is contained in:
steve-adminandClaude Sonnet 5 committed 2026-09-13 16:05:29 +00:00
1 parent e5233433b5
commit b5d2f2f19b
1 file changed
+18
+18
View File
@@ -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}") 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: def _ld_library_path_for_venv(venv_dir: Path) -> str:
site_packages = next(venv_dir.glob(".venv/lib/python*/site-packages")) site_packages = next(venv_dir.glob(".venv/lib/python*/site-packages"))
nvidia_dir = site_packages / "nvidia" nvidia_dir = site_packages / "nvidia"
@@ -123,6 +140,7 @@ def strip_vocals(input_audio: str):
def use_as_reference(audio_path: str, history: list): def use_as_reference(audio_path: str, history: list):
if not audio_path: if not audio_path:
raise gr.Error("No audio to use yet.") raise gr.Error("No audio to use yet.")
audio_path = _ensure_wav(audio_path)
history = [audio_path] history = [audio_path]
return audio_path, history, _history_label(history) return audio_path, history, _history_label(history)