Use librosa for loading mp3s

This commit is contained in:
James Betker 2022-05-03 20:44:31 -06:00
parent e981898de7
commit e23e6f6696

View File

@ -1,6 +1,7 @@
import os import os
from glob import glob from glob import glob
import librosa
import torch import torch
import torchaudio import torchaudio
import numpy as np import numpy as np
@ -26,9 +27,7 @@ def load_audio(audiopath, sampling_rate):
if audiopath[-4:] == '.wav': if audiopath[-4:] == '.wav':
audio, lsr = load_wav_to_torch(audiopath) audio, lsr = load_wav_to_torch(audiopath)
elif audiopath[-4:] == '.mp3': elif audiopath[-4:] == '.mp3':
# https://github.com/neonbjb/pyfastmp3decoder - Definitely worth it. audio, lsr = librosa.load(audiopath, sr=sampling_rate)
from pyfastmp3decoder.mp3decoder import load_mp3
audio, lsr = load_mp3(audiopath, sampling_rate)
audio = torch.FloatTensor(audio) audio = torch.FloatTensor(audio)
# Remove any channel data. # Remove any channel data.