How to clone, install and run the "audiohealth" program

About building audiohealth, particularly osbh-audioanalyzer in tools directory,
git complains with the error message “fatal: reference is not a tree” when using the “--recursive” option.
I went to tools directory, remove the osbh-audioanalyzer then:
git clone git@github.com:hiveeyes/osbh-audioanalyzer.git

and then:
git checkout inputfile-strategy

Thanks for reporting this, @Jodaille! And good to see you found a workaround in the meanwhile.

We just fixed the reference to the “osbh-audioanalyzer” git submodule to point to the most recent commit of the master branch. May we ask you humbly to try again?

Hello andreas,

it works ! :-)

Cool, thanks for the quick test!

Hello andreas,

can you please add virtualenv to Prerequisites packages paragraph ?

apt install python-scipy python-numpy sox libsox-fmt-all youtube-dl

in audiohealth/README.rst at main · hiveeyes/audiohealth · GitHub

Done per commit 1ba6088c. Thanks a bunch!

1 Like

Hello,

on OrangePI/Debian, some other packages seems required to generate the power spectrum :

xvfb-run and xauth

After having them installed I have this error :

(.venv27)jody@orangepipcplus:~/audiohealth$ xvfb-run audiohealth power --audiofile /tmp/new.wav --pngfile audio-power.png
Traceback (most recent call last):
  File "/home/jody/audiohealth/.venv27/bin/audiohealth", line 9, in <module>
    load_entry_point('audiohealth==0.4.0', 'console_scripts', 'audiohealth')()
  File "/home/jody/audiohealth/audiohealth.py", line 353, in main
    tmpfile   = power_spectrum(wavfile)
  File "/home/jody/audiohealth/audiohealth.py", line 218, in power_spectrum
    plt.rc('xtick', labelsize=10)
NameError: global name 'plt' is not defined

I have added python-matplotlib but same result.

Thanks for your feedback! We will improve the situation and add the packages to the prerequisite documentation.

You will probably have to remove and recreate the virtualenv with --system-site-packages after installing python-matplotlib

I have tried removing .venv27, I have also tried a new full setup starting from git

adding a debug message on exception in audiohealth.py I have the message about import

try:
    import matplotlib.pyplot as plt
except:
    print("Could not import pyplot")
    pass

I am a python beginner

Hmmm, sorry!

Did you “deactivate” the virtualenv before removing and recreating it followed by a second "source .venv27/bin/activate" to reactivate it again? Maybe another “python setup.py develop” is also required after activating it again…

Maybe also try pip install matplotlib while having the virtualenv activated (followed by another “python setup.py develop” - better safe than sorry). Then, Python will install the module inside the virtualenv without a dependency to the Linux distribution package. This will probably require a compiler and maybe other dependencies, though.

Thank for your help,

it seems already here :

(.venv27)jody@orangepipcplus:~/audiohealth$ pip install matplotlib 
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /usr/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): nose>=0.11.1 in /usr/lib/python2.7/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): mock in /usr/lib/python2.7/dist-packages (from matplotlib)

the --upgrade require more time to investigate, to be continued :-)

Sorry again!

As a last resort maybe try:

deactivate
apt remove python-matplotlib
# recreate virtualenv
source .venv27/bin/activate
pip install matplotlib 

… to not use the distribution matplotlib at all.

Note to self: Offer distribution packages for “audiohealth” (amd64 and armhf) for installations without any hassle :-).

Hello andreas and thank you for your help,

as you have asked I have removed matplotlib, after some tests and fails I think I have added this packages :

apt-get install pkg-config libfreetype6-dev python-dev

After successfull compilation, matplotlib seems well included in the script.

The new message I have is:

(.venv27)jody@orangepipcplus:~/audiohealth$ xvfb-run audiohealth power --audiofile /tmp/new.wav --pngfile audio-power.png
/home/jody/audiohealth/audiohealth.py:234: RuntimeWarning: invalid value encountered in sqrt
  plt.plot(f, np.sqrt(Pxx_spec), 'b')
==================
Peaks by frequency
==================

==============
Peaks by power
==============

========
Analysis
========
Traceback (most recent call last):
  File "/home/jody/audiohealth/.venv27/bin/audiohealth", line 9, in <module>
    load_entry_point('audiohealth==0.4.0', 'console_scripts', 'audiohealth')()
  File "/home/jody/audiohealth/audiohealth.py", line 354, in main
    tmpfile   = power_spectrum(wavfile)
  File "/home/jody/audiohealth/audiohealth.py", line 271, in power_spectrum
    freq500 = max(band500, key=peak_data.get)
ValueError: max() arg is an empty sequence

I have uploaded the file, maybe it could help you to make a diagnostic:

I have recorded it with:

arecord -f S16_LE -d30 -r 44100 -D hw:2,0 -c 1 /tmp/new.wav

I have tested with the ogg file to (same results):

xvfb-run audiohealth power --audiofile samples/swarm_-15_-5.ogg --pngfile audio-power.png

Thanks! I just tested the program with your audio sample and it seems to work on our machines:

$ xvfb-run audiohealth power --audiofile samples/jodaille_test.wav --pngfile samples/jodaille_test.png
==================
Peaks by frequency
==================
        1408.89 Hz            174.60 RMS

==============
Peaks by power
==============
         174.60 RMS           1408.89 Hz

The culprit most probably is the “RuntimeWarning: invalid value encountered in sqrt”, i don’t get this when running the program against your audio sample on a Debian and a Mac OSX machine. Maybe it’s about the scipy or numpy versions… Sorry again!

I will have a more detailed look when i’m back from vacation.

Dear Andreas,

I am dreaming about beehive sound study for years, it becomes real: many thanks to you.

On my workstation (Mac OSX) it says:

$ python

>>> import scipy
>>> scipy.version.version
'0.17.0'

>>> import numpy
>>> numpy.version.version
'1.10.4'

On our Debian machine, it says:

$ python

>>> import scipy
>>> scipy.version.version
'0.19.1'

>>> import numpy
>>> numpy.version.version
'1.10.4'

… both while having the virtualenv activated.

Can you compare these versions to your setup on the OrangePi, @Jodaille?

Hello Andreas,

on OrangePi with Debian Jessie

(.venv27)jody@orangepipcplus:~/audiohealth$ python
Python 2.7.9 (default, Aug 13 2016, 17:56:53) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> scipy.version.version
'0.14.0'
>>> import numpy
>>> numpy.version.version
'1.8.2'

It was pretty older than your versions, I have already update alsa-utils with stretch because 0.8
has arecord buggy and create multiple file with -d option
So I try to update python-scipy and python-numpy now I have :

>>> scipy.version.version
'0.18.1'
>>> numpy.version.version
'1.12.1'

but I does not like it :-)

Traceback (most recent call last):
  File "/home/jody/audiohealth/.venv27/bin/audiohealth", line 9, in <module>
    load_entry_point('audiohealth==0.4.0', 'console_scripts', 'audiohealth')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/home/jody/audiohealth/audiohealth.py", line 13, in <module>
    from scipy import signal
  File "/usr/lib/python2.7/dist-packages/scipy/signal/__init__.py", line 293, in <module>
    from .bsplines import *
  File "/usr/lib/python2.7/dist-packages/scipy/signal/bsplines.py", line 12, in <module>
    from scipy.special import comb, gamma
  File "/usr/lib/python2.7/dist-packages/scipy/special/__init__.py", line 643, in <module>
    from ._ellip_harm import ellip_harm, ellip_harm_2, ellip_normal
  File "/usr/lib/python2.7/dist-packages/scipy/special/_ellip_harm.py", line 7, in <module>
    from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
  File "scipy/special/_ellip_harm_2.pyx", line 5, in init scipy.special._ellip_harm_2 (scipy/special/_ellip_harm_2.c:7330)
  File "/usr/lib/python2.7/dist-packages/scipy/integrate/__init__.py", line 59, in <module>
    from ._bvp import solve_bvp
  File "/usr/lib/python2.7/dist-packages/scipy/integrate/_bvp.py", line 10, in <module>
    from scipy.sparse.linalg import splu
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/__init__.py", line 112, in <module>
    from .isolve import *
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
    from .iterative import *
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py", line 84, in <module>
    def bicg(A, b, x0=None, tol=1e-5, maxiter=None, xtype=None, M=None, callback=None):
  File "/usr/lib/python2.7/dist-packages/scipy/_lib/_threadsafety.py", line 59, in decorator
    return lock.decorate(func)
  File "/usr/lib/python2.7/dist-packages/scipy/_lib/_threadsafety.py", line 47, in decorate
    return scipy._lib.decorator.decorate(func, caller)
AttributeError: 'module' object has no attribute 'decorate'

I will install a full stretch version.

Thank you, and have some good vacations.

maybe the python decorator itself is missing or old?

>>> import decorator
>>> decorator.__version__

should show something like:

'3.4.0'
>>>

Dear Jody,

yes, either update to Debian Stretch or don’t use the virtualenv with the “--system-site-packages” option at all and install scipy and numpy from within the virtualenv. Using the distribution packages is “just” an optimization to save yourself compiling a huge stack of software on low-performance machines (you might have recognized that numpy and scipy are real power horses).

But it will also need some more dependencies like the Fortran compiler and more C/C++ libraries like BLAS, LAPACK and ATLAS, so it’s not an easy peasy route either. Also, even after satisfying all dependencies, the compilation process will probably take some minutes, maybe even hours :-).

If you don’t care about this and dare to go down this path, you might want to try:

# recreate "pure" virtualenv:
deactivate
rm -rf .venv27
virtualenv .venv27

# and finally:
source .venv27/bin/activate
pip install scipy --upgrade
pip install numpy --upgrade

With kind regards,
Andreas.

P.S.: Regarding dependencies, some bits of documentation about building the Kotori package (which also uses NumPy) can give you valuable hints:

# build foundation and header files
aptitude install -y build-essential python-dev libssl-dev libffi-dev libyaml-dev python-virtualenv

# build infrastructure
aptitude install -y python-setuptools

# scipy, numpy, matplotlib and PyTables
aptitude install -y pkg-config gfortran libatlas-dev libopenblas-dev liblapack-dev libhdf5-dev libnetcdf-dev liblzo2-dev libbz2-dev
aptitude install -y libpng12-dev libfreetype6-dev

P.P.S.: Again as a reminder for ourselves …

Dear Andreas,

I have started installing packages to go deeper,
when it asked me to upgrade glibc6 I have pressed Enter and just remember me that I have kept Stretch in sources.list :o

But then compilation of scipy fails I though it was about lib that were’nt updated so I have done a fully upgrade to stretch.

No luck, it take hours and the results is an enormous stack trace that I cannot see the begin.