Vansh Chugh commited on
Commit
7b11b09
·
1 Parent(s): 4bdf828

replace torchaudio.load() with sf.read()

Browse files
Files changed (1) hide show
  1. unison/pipelines/infer.py +11 -3
unison/pipelines/infer.py CHANGED
@@ -21,7 +21,6 @@ from typing import List, Optional
21
  import torch
22
  import torch.nn.functional as F
23
  import soundfile as sf
24
- import torchaudio
25
  import torchaudio.functional as AF
26
  from diffusers import FlowMatchEulerDiscreteScheduler
27
  from diffusers.training_utils import EMAModel
@@ -346,10 +345,19 @@ def _rms_normalize(wav: torch.Tensor, target_rms: float = TRAINING_TARGET_RMS) -
346
  return wav
347
 
348
 
 
 
 
 
 
 
 
 
 
349
  def load_source_audio(audio_path, target_sr=DEFAULT_TARGET_SAMPLE_RATE,
350
  target_length=None, max_duration=MAX_AUDIO_DURATION, device=None):
351
  device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
352
- wav, sr = torchaudio.load(audio_path)
353
  if wav.shape[0] > 1:
354
  wav = wav.mean(0, keepdim=True)
355
  if sr != target_sr:
@@ -519,7 +527,7 @@ def load_ref_audio(
519
  the ref's last formant.
520
  """
521
  device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
522
- wav, sr = torchaudio.load(audio_path)
523
  if wav.shape[0] > 1:
524
  wav = wav.mean(0, keepdim=True)
525
  if sr != target_sr:
 
21
  import torch
22
  import torch.nn.functional as F
23
  import soundfile as sf
 
24
  import torchaudio.functional as AF
25
  from diffusers import FlowMatchEulerDiscreteScheduler
26
  from diffusers.training_utils import EMAModel
 
345
  return wav
346
 
347
 
348
+ def _load_audio(audio_path):
349
+ """
350
+ Read an audio file into a [channels, samples] float32 tensor.
351
+ """
352
+ data, sr = sf.read(audio_path, dtype="float32", always_2d=True) # [samples, channels]
353
+ wav = torch.from_numpy(data.T) # [channels, samples]
354
+ return wav, sr
355
+
356
+
357
  def load_source_audio(audio_path, target_sr=DEFAULT_TARGET_SAMPLE_RATE,
358
  target_length=None, max_duration=MAX_AUDIO_DURATION, device=None):
359
  device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
360
+ wav, sr = _load_audio(audio_path)
361
  if wav.shape[0] > 1:
362
  wav = wav.mean(0, keepdim=True)
363
  if sr != target_sr:
 
527
  the ref's last formant.
528
  """
529
  device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
530
+ wav, sr = _load_audio(audio_path)
531
  if wav.shape[0] > 1:
532
  wav = wav.mean(0, keepdim=True)
533
  if sr != target_sr: