[Bug] Dub assembly fails with torchaudio 2.9: torchaudio.load routes through missing TorchCodec (dub_speech_missing)

Author: tokutei58301-boopCreated Sep 28, 2026Updated Sep 29, 2026

Environment

  • VoiceStudio 0.5.6, source install, commit 08a1592e (2026-09-27)
  • Windows 11 (10.0.26200), RTX 5060 Ti, driver 591.86
  • uv sync (lockfile-resolved): torch/torchaudio 2.9.1+cu128, transformers 5.15.1
  • torchcodec is not installed (not in uv.lock either)
  • Repro: POST /dub/upload → POST /dub/transcribe/{id} (OK) → POST /dub/generate/{id} (OK, TTS renders) → assembly fails

Summary

With the locked torchaudio 2.9.1, POST /dub/generate/{job_id} renders every segment's TTS fine but assembly always fails with error_code: "dub_speech_missing" ("A speech segment could not be read. Regenerate it before exporting."), because _load_entry_wav() calls torchaudio.load() on the on-disk seg_*.wav and torchaudio 2.9 routes that through TorchCodec, which is absent.

Actual behavior

Backend log (faulthandler-clean, plain ImportError chain):

[backend] 2026-09-28 10:50:57,362 WARNING [omnivoice.audio_io] torchaudio.save needs TorchCodec (...); writing via soundfile
[backend] 2026-09-28 10:50:57,394 ERROR [omnivoice.dub] Dub assembly could not read segment 0
[backend] ImportError: TorchCodec is required for load_with_torchcodec. Please install torchcodec to use this function.
[backend]   File "...dub_generate.py", line 1728, in _stream
[backend]     wav = _load_entry_wav((start, end, wav_path, sr), sr)
[backend]   File "...dub_generate.py", line 641, in _load_entry_wav
[backend]     wav, loaded_sr = torchaudio.load(entry[2])

The failing call is backend/api/routers/dub_generate.py _load_entry_wav() (~line 641 in my build):

python
def _load_entry_wav(entry, target_sr: int) -> torch.Tensor:
    if isinstance(entry[2], torch.Tensor):
        return entry[2]
    wav, loaded_sr = torchaudio.load(entry[2])   # ← torchaudio 2.9: routes through TorchCodec
    ...

Root cause

  • torchaudio 2.9 made torchaudio.load() a TorchCodec-routed call (torchaudio._torchcodec.load_with_torchcodec).
  • uv.lock never installs torchcodec, so on every uv sync / source install, torchaudio.load() raises ImportError.
  • The repo already handles the save side of this exact migration: services/audio_io.py documents the sox → soundfile → TorchCodec backend shift and _safe_soundfile_write guards torchaudio.save (the warning line above comes from that path, which is why TTS segments render fine). The load side was not covered.

Impact

  • Headless/API dubbing is fully blocked at assembly on any fresh uv sync install with the current lockfile (TTS, transcribe, translate all work).
  • There are ~10 other torchaudio.load call sites in backend/ (watermark.py, longform_render.py, persona_bundle.py, tts_backend.py, engine adapters, plus 4 more in dub_generate.py itself: seg-reuse at ~633, cached segs ~1006, remote results ~1457, RVC ~1540). They are latent instances of the same bug — the dub path just hits it first.

Proposed fix

Minimum fix that unblocked me (applied locally, then done end-to-end: sync score 0.718, two-track MP4 exported, round-trip ASR verified):

python
def _load_entry_wav(entry, target_sr: int) -> torch.Tensor:
    if isinstance(entry[2], torch.Tensor):
        return entry[2]
    try:
        wav, loaded_sr = torchaudio.load(entry[2])
    except ImportError:
        # torchaudio 2.9 routes load() through TorchCodec; when that wheel
        # is missing/broken, fall back to soundfile (segments here are
        # always plain PCM WAV written by the sibling soundfile save path).
        import soundfile as sf

        data, loaded_sr = sf.read(entry[2], dtype="float32", always_2d=True)
        wav = torch.from_numpy(data.T)
    if loaded_sr != target_sr:
        import torchaudio.functional as AF
        wav = AF.resample(wav, loaded_sr, target_sr)
    return wav

Suggested follow-ups for a durable fix (maintainer's call):

  1. Either pin/install torchcodec properly (it would also fix save performance parity), or introduce a shared services/audio_io.load_audio(path_or_buf) helper with the soundfile fallback and migrate all torchaudio.load call sites — mirroring the existing _safe_soundfile_write pattern in the same module.
  2. Consider a smoke test that calls torchaudio.load on a rendered segment so a lockfile bump that re-breaks this fails CI instead of users.

Happy to open a PR with either variant.

Verification

After the local patch, same job re-run end-to-end on the same machine:

data: {"type": "progress", "current": 0, "total": 1, ...}
data: {"type": "assembling"}
data: {"type": "done", "segments_processed": 1, "language_code": "vi", "tracks": ["vi"], "sync_scores": [0.718], "fit_status": [{"status": "fits"}], "timing_strategy": "concise", ...}

GET /dub/download/{job_id} returned a two-audio-track MP4; extracting the dub track and re-transcribing it through POST /transcribe confirms speech is present and timed correctly.

Source: debpalash/OmniVoice-Studio