[Bug] Dub assembly fails with torchaudio 2.9: torchaudio.load routes through missing TorchCodec (dub_speech_missing)
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.1torchcodecis not installed (not inuv.lockeither)- 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):
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.locknever installstorchcodec, so on everyuv sync/ source install,torchaudio.load()raisesImportError.- The repo already handles the save side of this exact migration:
services/audio_io.pydocuments the sox → soundfile → TorchCodec backend shift and_safe_soundfile_writeguardstorchaudio.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 syncinstall with the current lockfile (TTS, transcribe, translate all work). - There are ~10 other
torchaudio.loadcall sites inbackend/(watermark.py,longform_render.py,persona_bundle.py,tts_backend.py, engine adapters, plus 4 more indub_generate.pyitself: 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):
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 wavSuggested follow-ups for a durable fix (maintainer's call):
- Either pin/install
torchcodecproperly (it would also fixsaveperformance parity), or introduce a sharedservices/audio_io.load_audio(path_or_buf)helper with thesoundfilefallback and migrate alltorchaudio.loadcall sites — mirroring the existing_safe_soundfile_writepattern in the same module. - Consider a smoke test that calls
torchaudio.loadon 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