Download code/resample.py from rcell233/magvits_data: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/resample.py
- Command line
-
hf download hf://datasets/rcell233/magvits_data/code/resample.py
-
curl -L -o resample.py https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/resample.py
1.05 kB
| import os | |
| import shutil | |
| from glob import glob | |
| import librosa | |
| import soundfile | |
| from tqdm import tqdm | |
| from multiprocessing import Pool | |
| from data_conf import data_root | |
| def process_wav(wavpath): | |
| wav, _ = librosa.load(wavpath, sr=tgt_sr) | |
| soundfile.write(wavpath, wav, tgt_sr) | |
| def get_wav_files(path): | |
| wav_files = [] | |
| for root, dirs, files in os.walk(path): | |
| for file in files: | |
| if file.endswith(".wav") or file.endswith(".mp3"): | |
| wav_files.append(os.path.join(root, file)) | |
| return wav_files | |
| tgt_path = data_root | |
| num_processes = 10 # You can adjust the number of processes as needed | |
| tgt_sr = 32000 | |
| print("Note: this script will overwrite the original files!") | |
| print("all the wav files under {} will be resampled to {}Hz".format(tgt_path, tgt_sr)) | |
| input("press enter to continue... or press Ctrl+C to cancel") | |
| if __name__ == "__main__": | |
| with Pool(num_processes) as pool: | |
| file_list = get_wav_files(tgt_path) | |
| list(tqdm(pool.imap(process_wav, file_list), total=len(file_list))) | |