1

I'm trying to use TensorFlow Lite for a voice recognition project using Jupyter notebook but when I try to do a "import librosa" (using commands found here: https://github.com/ShawnHymel/tflite-speech-recognition/blob/master/01-speech-commands-mfcc-extraction.ipynb) I keep getting this error:

OSError: sndfile library not found

I've looked for a solution for two days now, tried many different things I've found online but I just can't seem to get it to work.

I'm using CentOS 8 and the tensorflow is running on a docker:

docker pull tensorflow/tensorflow:latest-py3-jupyter   
docker run -it --rm -v /home/server/Desktop/TensorFlow -p 8888:8888 tensorflow/tensorflow:latest-py3-jupyter

My requirements.txt is empty, at least when I do pip freeze > requirements.txt.

pip -V or --v returns this

pip 20.3.2 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

Trying to install pysndfile gives me this

ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-w_gdqebo/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools 'numpy>=1.13.0' 'cython>=0.25.0' wheel Check the logs for full command output.

I've tried different commands to fix this error and to install the sndfile but all of them have given errors or simply said it's already installed.

I do have librosa installed but trying to import it gives me this full error:

 OSError                                   Traceback (most recent call last)
<ipython-input-10-989066361697> in <module>
----> 1 import librosa

/usr/local/lib/python3.6/dist-packages/librosa/__init__.py in <module>
    209 # And all the librosa sub-modules
    210 from ._cache import cache
--> 211 from . import core
    212 from . import beat
    213 from . import decompose

/usr/local/lib/python3.6/dist-packages/librosa/core/__init__.py in <module>
      4 
      5 from .convert import *  # pylint: disable=wildcard-import
----> 6 from .audio import *  # pylint: disable=wildcard-import
      7 from .spectrum import *  # pylint: disable=wildcard-import
      8 from .pitch import *  # pylint: disable=wildcard-import

/usr/local/lib/python3.6/dist-packages/librosa/core/audio.py in <module>
      6 import warnings
      7 
----> 8 import soundfile as sf
      9 import audioread
     10 import numpy as np

/usr/local/lib/python3.6/dist-packages/soundfile.py in <module>
    140     _libname = _find_library('sndfile')
    141     if _libname is None:
--> 142         raise OSError('sndfile library not found')
    143     _snd = _ffi.dlopen(_libname)
    144 except OSError:

OSError: sndfile library not found

Anyone got ideas on how to sort this?

Jaacob
  • 27
  • 1
  • 5

1 Answers1

3

Install sndfile for your operating system. On CentOS that should be yum install libsndfile.

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50
  • It says it's already installed. Very strange to me. Goes beyond my knowledge. – Jaacob Dec 15 '20 at 20:25
  • Try to also add the -dev / -devel package – Jon Nordby Dec 15 '20 at 22:42
  • Are you installing it *inside* your Docker image? – Jon Nordby Dec 15 '20 at 22:43
  • I installed -devel on the root but no luck. I also tried executing it within the docker: "docker exec -it 1e18ef5ff2aa yum localinstall http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/libsndfile-devel-1.0.28-10.el8.x86_64.rpm" Am I indeed supposed to install it into the docker, and am I even trying to install it right? – Jaacob Dec 15 '20 at 23:49
  • Edit: I realized I needed to throw the bash cmd first and then try to install it. But none of the install cmds were found so before I dig deeper into that, just wanna make sure if I was supposed to install it to the docker. – Jaacob Dec 16 '20 at 00:11
  • Yes if your Python process executes from Jupyter inside the Docker, then all dependencies must also go inside the Docker image. The tensorflow Docker image is probably not based on CentOS. Ubuntu/Debian or Alpine more likely. It may be the best to write a Dockerfile to run the steps at image build time instead of at runtime. – Jon Nordby Dec 16 '20 at 08:58
  • 1
    It finally worked! I made a new dockerfile where I used TensorFlow as the base image and then added the said installations to RUN. The imports work perfectly now. Thank you!! – Jaacob Dec 17 '20 at 10:36
  • Ok. I should probably update my answer to include those instructions then – Jon Nordby Dec 17 '20 at 11:30