Spaces:
Running
Running
Download acestep/training/dataset_builder_modules/preprocess_audio.py from adowu/ACE-Step-Training: direct link, hf CLI and curl.
- Browser
- Download file 635 Bytes
-
https://huggingface.co/spaces/adowu/ACE-Step-Training/resolve/main/acestep/training/dataset_builder_modules/preprocess_audio.py
- Command line
-
hf download hf://spaces/adowu/ACE-Step-Training/acestep/training/dataset_builder_modules/preprocess_audio.py
-
curl -L -o preprocess_audio.py https://huggingface.co/spaces/adowu/ACE-Step-Training/resolve/main/acestep/training/dataset_builder_modules/preprocess_audio.py
635 Bytes
| import torchaudio | |
| def load_audio_stereo(audio_path: str, target_sample_rate: int, max_duration: float): | |
| """Load audio, resample, convert to stereo, and truncate.""" | |
| audio, sr = torchaudio.load(audio_path) | |
| if sr != target_sample_rate: | |
| resampler = torchaudio.transforms.Resample(sr, target_sample_rate) | |
| audio = resampler(audio) | |
| if audio.shape[0] == 1: | |
| audio = audio.repeat(2, 1) | |
| elif audio.shape[0] > 2: | |
| audio = audio[:2, :] | |
| max_samples = int(max_duration * target_sample_rate) | |
| if audio.shape[1] > max_samples: | |
| audio = audio[:, :max_samples] | |
| return audio, sr | |