torchaudio should use proper backend to load audio (#3179)

This commit is contained in:
Gorkem 2023-11-09 18:28:39 +03:00 committed by GitHub
parent 46d9c27212
commit 66a1e248d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -69,12 +69,9 @@ def wav_to_mel_cloning(
def load_audio(audiopath, sampling_rate): def load_audio(audiopath, sampling_rate):
# better load setting following: https://github.com/faroit/python_audio_loading_benchmark # better load setting following: https://github.com/faroit/python_audio_loading_benchmark
if audiopath[-4:] == ".mp3":
# it uses torchaudio with sox backend to load mp3 # torchaudio should chose proper backend to load audio depending on platform
audio, lsr = torchaudio.backend.sox_io_backend.load(audiopath) audio, lsr = torchaudio.load(audiopath)
else:
# it uses torchaudio soundfile backend to load all the others data type
audio, lsr = torchaudio.backend.soundfile_backend.load(audiopath)
# stereo to mono if needed # stereo to mono if needed
if audio.size(0) != 1: if audio.size(0) != 1: