Fixes #3178 - Librosa requires 1-dimensional array for mono samples

This commit is contained in:
Tilman Kamp 2020-07-23 17:18:40 +02:00
parent 38f6afdba8
commit ecbdf46940
1 changed files with 7 additions and 2 deletions

View File

@ -349,8 +349,13 @@ class Resample(SampleAugmentation):
audio = sample.audio audio = sample.audio
orig_len = len(audio) orig_len = len(audio)
audio = np.swapaxes(audio, 0, 1) audio = np.swapaxes(audio, 0, 1)
audio = resample(audio, sample.audio_format.rate, rate) if audio.shape[0] < 2:
audio = resample(audio, rate, sample.audio_format.rate) # since v0.8 librosa enforces a shape of (samples,) instead of (channels, samples) for mono samples
resampled = resample(audio[0], sample.audio_format.rate, rate)
audio[0] = resample(resampled, rate, sample.audio_format.rate)[:orig_len]
else:
audio = resample(audio, sample.audio_format.rate, rate)
audio = resample(audio, rate, sample.audio_format.rate)
audio = np.swapaxes(audio, 0, 1)[0:orig_len] audio = np.swapaxes(audio, 0, 1)[0:orig_len]
sample.audio = audio sample.audio = audio