Merge pull request #3179 from tilmankamp/fix-for-librosa

Fixes #3178 - Librosa requires 1-dimensional array for mono samples
This commit is contained in:
Tilman Kamp 2020-07-24 14:32:17 +02:00 committed by GitHub
commit 15a624134a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -349,6 +349,11 @@ class Resample(SampleAugmentation):
audio = sample.audio
orig_len = len(audio)
audio = np.swapaxes(audio, 0, 1)
if audio.shape[0] < 2:
# 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]