3

No matter how I import my audio file (through uploading it on google colab, importing it through google drive), I keep getting the same error. Could it be a path issue, and if so, how could I go about fixing it? When I run an "iPython.display", it displays the audio and I'm able to play it, but I'm not sure why torchaudio cannot load it.

Thanks in advance :)

waveform, sample_rate = torchaudio.load("Default-20220816-113844.mp3")
waveform = waveform.to(device)

if sample_rate != bundle.sample_rate:
    waveform = torchaudio.functional.resample(waveform, sample_rate, bundle.sample_rate)
ihavenoidea
  • 41
  • 1
  • 3
  • Update: I tried with a wav file too but I'm still getting the same error. – ihavenoidea Aug 16 '22 at 19:48
  • Have you tried the advice in [this link](https://lightrun.com/answers/huggingface-transformers-----raise-runtimeerrorfailed-to-load-audio-from-formatfilepath)? Specifically, `apt-get install sox` and `pip install "touchaudio<0.12.0"` ? – Jakob Lindskog Sep 27 '22 at 20:47
  • !add-apt-repository -y ppa:savoury1/ffmpeg4 !apt-get -qq install -y ffmpeg For the mp3 support, as of this date I'm assuming you tried waveform, sample_rate = torchaudio.load("/content/Default-20220816-113844.mp3") as well... – twobob Oct 16 '22 at 15:55

2 Answers2

3

At the time of the question is posted, Google Colab has pytorch==1.12 and torchaudio==0.12 pre-installed, so I assume you are getting the error with these versions.

Starting from TorchAudio 0.12, mp3 decoding requires FFmpeg. When "sox_io" backend is used, first it tries to load audio using libsox, and when it fails, it further tries to load it with FFmpeg.

In Google Colab, you can run the following command to install the supported version.

!add-apt-repository -y ppa:savoury1/ffmpeg4
!apt-get -qq install -y ffmpeg

See also: https://pytorch.org/audio/0.12.1/tutorials/streaming_api_tutorial.html

moto
  • 166
  • 1
  • 3
0

Assuming ("Default-20220816-113844.mp3") is not being found because of the path

On Colab to find the path click on the "..." (that appears on the right hand side of objects in the file browser when you hover over them) and choose COPY PATH to copy the complete path, the value will be copied without quotation marks.

Colab file browser showing copy path option

enter image description here

twobob
  • 354
  • 8
  • 22