SoulX-Singer / soulxsinger /utils /audio_utils.py
Xinsheng-Wang's picture
Upload folder using huggingface_hub
c7f3ffb verified
raw
history blame contribute delete
628 Bytes
import torch
import torchaudio
def load_wav(wav_path: str, sample_rate: int):
"""Load wav file and resample to target sample rate.
Args:
wav_path (str): Path to wav file.
sample_rate (int): Target sample rate.
Returns:
torch.Tensor: Waveform tensor with shape (1, T).
"""
waveform, sr = torchaudio.load(wav_path)
if sr != sample_rate:
waveform = torchaudio.functional.resample(waveform, sr, sample_rate)
if len(waveform.shape) > 1 and waveform.shape[0] > 1:
waveform = torch.mean(waveform, dim=0, keepdim=True)
return waveform