pool
:
with Pool(os.cpu_count() - 1) as p:
N = len(fpaths)
p.starmap(resample, zip(fpaths, new_paths, [sr] * N, ['WAV'] * N, [manifest] * N))
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/opt/conda/lib/python3.7/multiprocessing/pool.py", line 47, in starmapstar
return list(itertools.starmap(args[0], args[1]))
File "/home/jupyter/jn-kaggle/birdsong/who-said-what/wsw/preprocessing.py", line 35, in resample
audio, sr = librosa.load(old_path, sr=sr)
File "/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py", line 172, in load
y = resample(y, sr_native, sr, res_type=res_type)
File "/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py", line 553, in resample
ratio = float(target_sr) / orig_sr
ZeroDivisionError: float division by zero
"""
我想处理这个错误,但是,我所尝试的似乎不起作用:
def resample(old_path, new_path, sr, ext='WAV', manifest=None):
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
print(f'Loading {old_path}',)
audio, sr = librosa.load(old_path, sr=sr)
except ZeroDivisionError:
audio, sr = librosa.load(old_path, sr=None)
print(f'Error loading file at {old_path}. file=sys.stderr)
我知道零除法误差是由
librosa.load()