-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresample.py
executable file
·38 lines (34 loc) · 1.16 KB
/
resample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import librosa
import glob
import soundfile as sf
import os
import concurrent.futures
from tqdm import tqdm
import traceback
from shutil import copy2
def func(fname):
audio, sr = librosa.load(fname, sr=None)
if sr != 16000:
print("resampling", fname)
audio = librosa.resample(audio, orig_sr=sr, target_sr=16000)
sf.write(
fname.replace(".flac", "_16k.wav"),
audio,
16000,
"PCM_24"
)
for item in ["train", "validation", "test"]:
print(f"Settling {item}..")
dir = sorted(glob.glob(f"/workspace/data/dataset/slakh2100_flac_redux/{item}/**/mix.flac"))
pbar = tqdm(total=len(dir))
with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
# Start the load operations and mark each future with its URL
future_to_fname = {executor.submit(func, fname): fname for fname in dir}
for future in concurrent.futures.as_completed(future_to_fname):
try:
fname = future_to_fname[future]
audio = future.result()
pbar.update()
except Exception as e:
traceback.print_exc()
print("Done.")