BoxOfColors commited on
Commit
addc08f
·
1 Parent(s): 0a5362f

Save output WAVs via soundfile instead of torchaudio.save

Browse files

torchaudio 2.11 removed its old save backends in favor of torchcodec,
which isn't installed, so torchaudio.save() raised ImportError on the
very last step of every generation. soundfile is already a pinned
dependency and needs no extra backend.

Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -26,6 +26,7 @@ from pathlib import Path
26
  import torch
27
  import numpy as np
28
  import torchaudio
 
29
  import ffmpeg
30
  import spaces
31
  import gradio as gr
@@ -1039,11 +1040,10 @@ def _stitch_wavs(wavs: list[np.ndarray], crossfade_s: float, db_boost: float,
1039
 
1040
 
1041
  def _save_wav(path: str, wav: np.ndarray, sr: int) -> None:
1042
- """Save a numpy wav array to *path* as stereo (2, T) via torchaudio.
1043
  Always conforms to stereo so every output WAV is a proper 2-channel file."""
1044
  wav = _to_stereo(wav) # (1,T) or (T,) → (2,T); (2,T) is a no-op
1045
- t = torch.from_numpy(np.ascontiguousarray(wav))
1046
- torchaudio.save(path, t, sr)
1047
 
1048
 
1049
  def _log_inference_timing(label: str, elapsed: float, n_segs: int,
 
26
  import torch
27
  import numpy as np
28
  import torchaudio
29
+ import soundfile as sf
30
  import ffmpeg
31
  import spaces
32
  import gradio as gr
 
1040
 
1041
 
1042
  def _save_wav(path: str, wav: np.ndarray, sr: int) -> None:
1043
+ """Save a numpy wav array to *path* as stereo (2, T) via soundfile.
1044
  Always conforms to stereo so every output WAV is a proper 2-channel file."""
1045
  wav = _to_stereo(wav) # (1,T) or (T,) → (2,T); (2,T) is a no-op
1046
+ sf.write(path, np.ascontiguousarray(wav.T), sr)
 
1047
 
1048
 
1049
  def _log_inference_timing(label: str, elapsed: float, n_segs: int,