6

I am trying to read Mp3 audio from URL using Librosa. I understand that Librosa first uses PySoundFile to load the audio and if that fails it then uses audioread.

I have the following code so far:

import librosa
import io
from six.moves.urllib.request import urlopen

url = "https://sneezoramafunction.blob.core.windows.net/usersounds/00bd9b8c914947d48724fd7e0c88041b.mp3"

data, samplerate = librosa.load(io.BytesIO(urlopen(url).read()))

But this gives me the following error:

RuntimeError: Error opening <_io.BytesIO object at 0x1c234747d0>: File contains data in an unknown format.

Additionally, I would be deploying this on Azure ML service and would not have any local storage available.

Thank you all for any help/advice

Singhal2
  • 450
  • 7
  • 22

2 Answers2

2

I don't think Librosa can take an object of type BytesIO and process it by itself. You may need to save it locally (wav/mp3) and then load using Librosa.

z = io.BytesIO(urlopen(url).read())
import pathlib
pathlib.Path(('/home/<name>/sneeze.wav').write_bytes(z.getbuffer())
data, sr = librosa.load('/home/<name>/sneeze.wav')
  • 1
    Hi, thank you for your answer. I should have mentioned that I would be deploying this on Azure ML service and would not have any local storage available. I would add this to the question. – Singhal2 Jul 01 '20 at 04:52
  • hello, Singhal2, I'm working on a audio problem using librosa and I was wondering what technique you're using to deploy to Azure ML service. care to share some pointers? – Samuel Tosan Ayo May 25 '23 at 23:30
2

librosa uses soundfile and audioread to load audio files. Note that soundfile does not currently support MP3, which will cause librosa to fall back on the audioread library.