multimodalart HF Staff commited on
Commit
ef045eb
·
verified ·
1 Parent(s): d1c33d5

Write WAV via soundfile (torchaudio 2.10 delegates save to torchcodec)

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -57,6 +57,26 @@ logger.info("Release assets ready in %.1fs at %s", time.time() - _t0, RELEASE_RO
57
  os.environ["OMNIVAE_RELEASE_ROOT"] = RELEASE_ROOT
58
  CHECKPOINT_DIR = os.path.join(RELEASE_ROOT, "models", "dit", "t2av", EXPERIMENT)
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  from t2av_pipeline import generate_one_av, load_joint_av_pipeline # noqa: E402
61
 
62
  # ---------------------------------------------------------------------------
 
57
  os.environ["OMNIVAE_RELEASE_ROOT"] = RELEASE_ROOT
58
  CHECKPOINT_DIR = os.path.join(RELEASE_ROOT, "models", "dit", "t2av", EXPERIMENT)
59
 
60
+ import torchaudio # noqa: E402
61
+
62
+ try: # pragma: no cover
63
+ import torchcodec # noqa: F401
64
+ except ImportError:
65
+ # torchaudio >= 2.10 delegates `save` to torchcodec, which is not installed
66
+ # (its wheels are pinned to a specific FFmpeg ABI). The pipeline only needs
67
+ # a plain 48 kHz WAV write, so route it through soundfile instead.
68
+ import numpy as _np # noqa: E402
69
+ import soundfile as _sf # noqa: E402
70
+
71
+ def _save_with_soundfile(uri, src, sample_rate, **_kwargs):
72
+ data = src.detach().to("cpu", torch.float32).numpy()
73
+ if data.ndim == 2: # torchaudio is (channels, time); soundfile wants (time, channels)
74
+ data = data.T
75
+ _sf.write(str(uri), _np.ascontiguousarray(data), int(sample_rate))
76
+
77
+ torchaudio.save = _save_with_soundfile
78
+ logger.info("torchcodec unavailable; torchaudio.save patched to use soundfile")
79
+
80
  from t2av_pipeline import generate_one_av, load_joint_av_pipeline # noqa: E402
81
 
82
  # ---------------------------------------------------------------------------