Home > Net >  Librosa libray [Python] resample function on Azure Function
Librosa libray [Python] resample function on Azure Function

Time:11-17

I am using librosa to resample the audio data, like below:

import librosa
filename = "/home/.../example.mp3"
audio, samplerate = librosa.load(filename) # samplerate = 48000
target_samplerate = 24000
new_audio = librosa.resample(audio,samplerate ,target_samplerate ,res_type='sinc_fastest')

This code works in my local linux system. However, when I deploy such code to the Azure function, it outputs Error: OSError: sndfile library not found Stack

The reason should be the librosa.resample function needs two C build Libs: Libsndfile and Libsamplerate. I can install them on my local linux system:

For Libsndfile:

sudo apt-get libsndfile1
sudo apt-get libsndfile-dev

For Libsamplerate: I first download the file from github: https://github.com/libsndfile/libsamplerate Then just follow the install instruction:

./configure
make
make check
make install

But how to install these two Libs on Azure function? Please give me some help! Thank you very much!

CodePudding user response:

By default, Azure Function on Linux runs in a default container. So Installing via apt-get install libsndfile1 & apt-get install libsndfile-dev in the Function host would have no effect on what's inside the container. For such scenario, you should consider Creating function using a custom container.

  • You can use a Function base image for python from here
  • In the docker file provided above, you would see several apt-get installation depending on what image you choose. Just add your required dependency (libsndfile1,libsndfile-dev in this case).
  • Build and deploy your function referring the guide.

Note: Custom image is not supported in Consumption plan. It would need Premium plan or a Dedicated (App Service) plan.

  • Related