ayf3 commited on
Commit
65cc5a2
·
verified ·
1 Parent(s): 9de82fd

Fix: replace torchaudio.load with soundfile.read to avoid torchcodec dependency error

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -325,11 +325,11 @@ class VoiceCloner:
325
  self._ensure_hifigan()
326
 
327
  try:
328
- y, sr = torchaudio.load(input_audio)
329
- if y.shape[0] > 1:
330
- y = y.mean(dim=0)
331
- else:
332
- y = y.squeeze(0)
333
  if sr != self.sample_rate:
334
  y = torchaudio.transforms.Resample(sr, self.sample_rate)(y)
335
  sr = self.sample_rate
 
325
  self._ensure_hifigan()
326
 
327
  try:
328
+ # Use soundfile directly to avoid torchaudio torchcodec backend issues
329
+ audio_data, sr = sf.read(input_audio, dtype='float32')
330
+ if audio_data.ndim > 1:
331
+ audio_data = audio_data.mean(axis=1)
332
+ y = torch.from_numpy(audio_data)
333
  if sr != self.sample_rate:
334
  y = torchaudio.transforms.Resample(sr, self.sample_rate)(y)
335
  sr = self.sample_rate