开源项目介绍-02 Aubio【1】环境配置和使用 @ Ubuntu + Pycharm + Python

发布于:2024-05-10 ⋅ 阅读:(19) ⋅ 点赞:(0)

前言:

aubio 是一组算法和工具,用于标记和变换音乐和声音。它扫描或监听音频信号,并尝试识别音乐事件。例如,当鼓被击打时,它能检测到音符的频率,或者一个有节奏的旋律的节拍是多少。

aubio 的功能包括:

  • 在每次打击前对声音文件进行分割
  • 进行音高检测
  • 敲击节奏
  • 从现场音频产生 MIDI 流

  • Python版本的配置和使用:

  • 按照官网的说法,异常简单,但是,。。。。。

笔者的工作目录:github,下载后解压,

K:\Prj_EDU\Sw_Proj\Aubio_python

 1 python + pycharm 版本@windows:【失败】

$ python -c "import aubio; print(aubio.version, aubio.float_type)"

 如果没有安装:

1.1 安装AUBIO

1.1.0 用pip安装aubio,错误,笔者没有实现:

错误如下:

Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.mirrors.ustc.edu.cn/simple/, https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/, http://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.org/simple/
Collecting aubio
  Using cached aubio-0.4.9.tar.gz (479 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in k:\prj_edu\sw_proj\aubio_python\aubio_python\.venv\lib\site-packages (from aubio) (1.26.4)
Building wheels for collected packages: aubio
  Building wheel for aubio (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [42 lines of output]

      K:\Prj_EDU\Sw_Proj\Aubio_python\Aubio_Python\.venv\lib\site-packages\setuptools\__init__.py:81: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.
      !!

              ********************************************************************************
              Requirements should be satisfied by a PEP 517 installer.
              If you are using pip, you can try `pip install --use-pep517`.
              ********************************************************************************

      !!
        dist.fetch_build_eggs(dist.setup_requires)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-39
      creating build\lib.win-amd64-cpython-39\aubio
      copying python\lib\aubio\cmd.py -> build\lib.win-amd64-cpython-39\aubio
      copying python\lib\aubio\cut.py -> build\lib.win-amd64-cpython-39\aubio
      copying python\lib\aubio\midiconv.py -> build\lib.win-amd64-cpython-39\aubio
      copying python\lib\aubio\slicing.py -> build\lib.win-amd64-cpython-39\aubio
      copying python\lib\aubio\__init__.py -> build\lib.win-amd64-cpython-39\aubio
      running build_ext
      checking for aubio = 0.4.9
      Running "pkg-config --libs --cflags aubio = 0.4.9" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      Info: aubio 0.4.9 was not found by pkg-config

      Info: looking for *optional* additional packages
      checking for libavcodec
      Running "pkg-config --libs --cflags libavcodec" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for libavformat
      Running "pkg-config --libs --cflags libavformat" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for libavutil
      Running "pkg-config --libs --cflags libavutil" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for libswresample
      Running "pkg-config --libs --cflags libswresample" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for libavresample
      Running "pkg-config --libs --cflags libavresample" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for sndfile
      Running "pkg-config --libs --cflags sndfile" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      checking for samplerate
      Running "pkg-config --libs --cflags samplerate" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      Info: libaubio was not installed or built locally with waf, adding src/
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for aubio
  Running setup.py clean for aubio
Failed to build aubio
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (aubio)
 

尝试用,python-pip的包管理

(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python\Aubio_Python> pip install python-pip
Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.mirrors.ustc.edu.cn/simple/, https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/, http://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.org/simple/
Collecting python-pip
  Downloading python_pip-1.1.1-py3-none-any.whl.metadata (1.9 kB)
Downloading python_pip-1.1.1-py3-none-any.whl (4.7 kB)
Installing collected packages: python-pip
Successfully installed python-pip-1.1.1
(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python\Aubio_Python> 
 

结果和上面错误一样,没有用。

1.1.1 用conda安装:【笔者安装了,但是不知道为何,无法使用,或者不知道如何实验,未来在研究吧】
(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python> conda config --add channels conda-forge
(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python> conda install -c conda-forge aubio

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    aubio-0.4.9                |   py37hdcea730_5         256 KB  conda-forge
    ffmpeg-4.3.1               |       ha925a31_0        26.2 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        26.4 MB

The following NEW packages will be INSTALLED:

  aubio              conda-forge/win-64::aubio-0.4.9-py37hdcea730_5 None
  ffmpeg             conda-forge/win-64::ffmpeg-4.3.1-ha925a31_0 None
  python_abi         conda-forge/win-64::python_abi-3.7-2_cp37m None


Proceed ([y]/n)?


Downloading and Extracting Packages
aubio-0.4.9          | 256 KB    | ############################################################################################################################################################################################ | 100%
ffmpeg-4.3.1         | 26.2 MB   | ############################################################################################################################################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Retrieving notices: ...working... done
 

1.1.2 pip安装
$ pip install pytest

 在    Pycharm的调试如下:

$ git clone https://git.aubio.org/aubio/aubio
$ cd aubio
$ pytest

参考: 

Python documentation — aubio 0.4.9 documentation


 2 Python版本 pycharm @Linux  Ubuntu的版本 【成功】


项目地址:

frank@frank-virtual-machine:~/Projects/PythonAubio/PrjAubio$ 

2.1 在ubuntu上安装pycharm(略)

2.2 配置环境:

2.2.1 安装numpy

 pip install numpy

遇到问题:

(.venv) frank@frank-virtual-machine:~/Projects/PythonAubio/PrjAubio$ pip install numpy

ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy

解决:

1 安装 python-pip
sudo apt-get install python-pip
2 用pip安装numpy,并采用清华的安装包源:
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

【案]如果直接用pip install numpy 会报错:

2.2.2 直接安装:aubio

pip install aubio

Collecting aubio
  Downloading aubio-0.4.9.tar.gz (479 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 479.0/479.0 kB 21.6 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in ./.venv/lib/python3.10/site-packages (from aubio) (1.26.4)
Building wheels for collected packages: aubio
  Building wheel for aubio (setup.py) ... done
  Created wheel for aubio: filename=aubio-0.4.9-cp310-cp310-linux_x86_64.whl size=380355 sha256=cabcdaf2ab3bffd631e1fa78608ec6b7857393070e7eebb68108a886c960741a
  Stored in directory: /home/frank/.cache/pip/wheels/00/30/30/a06fe7e9c7fe740486c219851b2bc1c7ed4a97e9c257efd3d7
Successfully built aubio
Installing collected packages: aubio
Successfully installed aubio-0.4.9
 

2.3 使用aubio:

2.3.1 进入aubio/python/demo目录:

2.3.2 使用python版本的工具:

2.3.2.1 py确认系统安装的python的可用版本
 2.3.2.2 运行一个demo

(.venv) frank@frank-virtual-machine:~/Projects/aubio/aubio/python/demos$ python3 demo_pitch.py
Usage: demo_pitch.py <filename> [samplerate]
 

【会给出使用技巧】

python3 demo_pitch.py TestAudio/1.wav 48000

 0.000000 0.000000 0.000000
0.010667 0.000000 0.000000
0.021333 0.000000 0.000000
0.032000 0.000000 0.000000
0.042667 0.000000 0.000000
0.053333 0.000000 0.000000
0.064000 0.000000 0.000000
0.074667 0.000000 0.000000
0.085333 0.000000 0.000000
0.096000 0.000000 0.000000
0.106667 0.000000 0.000000
0.117333 0.000000 0.000000
0.128000 20.157473 0.000000
0.138667 25.830223 0.000000
0.149333 34.323399 0.000000
0.160000 51.689980 0.000000
0.170667 162.232635 0.000000
0.181333 162.232635 0.000000
0.192000 162.232635 0.000000
0.202667 162.232635 0.000000
0.213333 138.269699 0.270921
0.224000 138.326996 0.249590
0.234667 138.321472 0.244399
0.245333 162.232635 0.000000

报错,audio的图像画的时候,确实python, matplotlib包:

  2.3.2.3  安装matplotlib

(.venv) frank@frank-virtual-machine:~/Projects/aubio/aubio/python/demos$ pip install matplotlib
ERROR: Could not find a version that satisfies the requirement matplotlib (from versions: none)
ERROR: No matching distribution found for matplotlib

[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: pip install --upgrade pip
 

提升pip的版本有点低,

解决,先sudo apt update更新包的List,

然后,sudo apt install python3-pip

【案] linux 系统的好处,就是配置开源环境的时候,比windows的系统,方便太多,

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python-pkg-resources python-setuptools python2 python2-minimal python2.7 python2.7-minimal
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python-pip
The following NEW packages will be installed:
  python3-pip
0 upgraded, 1 newly installed, 1 to remove and 113 not upgraded.
Need to get 1,305 kB of archives.
After this operation, 2,153 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-pip all 22.0.2+dfsg-1ubuntu0.4 [1,305 kB]
Fetched 1,305 kB in 2s (524 kB/s)      
debconf: unable to initialize frontend: Dialog
debconf: (Dialog frontend requires a screen at least 13 lines tall and 31 columns wide.)
debconf: falling back to frontend: Readline
(Reading database ... 187860 files and directories currently installed.)
Removing python-pip (20.3.4+dfsg-4) ...

Progress: [  0%] [.....................................................................................................................................................................................................................................................................................] 
Progress: [ 14%] [#######################################..............................................................................................................................................................................................................................................] 
Selecting previously unselected package python3-pip.#############################################......................................................................................................................................................................................................] 
(Reading database ... 187359 files and directories currently installed.)
Preparing to unpack .../python3-pip_22.0.2+dfsg-1ubuntu0.4_all.deb ...

Unpacking python3-pip (22.0.2+dfsg-1ubuntu0.4) ...######################################################################################...............................................................................................................................................................] 

Setting up python3-pip (22.0.2+dfsg-1ubuntu0.4) ...#############################################################################################################################.......................................................................................................................] 

Progress: [ 71%] [#####################################################################################################################################################################################################................................................................................] 
Processing triggers for man-db (2.10.2-1) ...##################################################################################################################################################################################################################........................................] 
 

然后,安装matplotlib

(.venv) frank@frank-virtual-machine:~/Projects/aubio/aubio/python/demos$ pip3 install matplotlib

【案,由于源的问题,会报错】

改为,

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple/ matplotlib

2.3.3 使用demo_notes。py 找到一段音乐的音调:

【案,笔者先录制了一段D4调号的钢琴音乐,然后,用识别软件进行测试,结果如下]

(.venv) frank@frank-virtual-machine:~/Projects/aubio/aubio/python/demos$ python3 demo_notes.py TestAudio/1_D4.wav 
    time [ start vel last ]
1.578957 [ 62. 110.  -1.]
D4
4.620771 [ 62. 110.   0.]
D4
7.407166 [ 62. 110.   0.]
D4
 

由此,LINUX环境下的配置成功完结。


参考:

GitHub - aubio/aubio: a library for audio and music analysis


问题:

1 下载aubio的问题:

(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python> git clone https://git.aubio.org/aubio/aubio
程序“git.exe”无法运行: 拒绝访问。所在位置 行:1 字符: 1
+ git clone https://git.aubio.org/aubio/aubio
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~。
所在位置 行:1 字符: 1
+ git clone https://git.aubio.org/aubio/aubio
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed
 

 【解决】如果不能自动下载,我们手动下载,然后,把源码Copy到对应的文件夹也可。

2 Python包的问题:

(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python> pytest
========================================================================================================= test session starts =========================================================================================================
platform win32 -- Python 3.9.5, pytest-8.2.0, pluggy-1.5.0
rootdir: K:\Prj_EDU\Sw_Proj\Aubio_python
collected 0 items / 29 errors                                                                                                                                                                                                          

=============================================================================================================== ERRORS ================================================================================================================ 
_____________________________________________________________________________________________ ERROR collecting python/tests/test_aubio.py _____________________________________________________________________________________________ 
ImportError while importing test module 'K:\Prj_EDU\Sw_Proj\Aubio_python\python\tests\test_aubio.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
D:\Programs\Python\Python39\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
python\tests\test_aubio.py:3: in <module>
    from numpy.testing import TestCase
E   ModuleNotFoundError: No module named 'numpy'
 

___________________________________________________________________________________________ ERROR collecting python/tests/test_aubio_cut.py ___________________________________________________________________________________________ 
ImportError while importing test module 'K:\Prj_EDU\Sw_Proj\Aubio_python\python\tests\test_aubio_cut.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
D:\Programs\Python\Python39\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
python\tests\test_aubio_cut.py:3: in <module>
    import aubio.cut
E   ModuleNotFoundError: No module named 'aubio'
 

【案】大部分报了aubio,和 numpy的包的错误 ,正确安装即可

3  pip install aubio问题:

3.1 pip install aubio报错:

 解决办法,

(.venv) PS K:\Prj_EDU\Sw_Proj\Aubio_python> .\setup.py clean

4 本地编译器版本太低:

      Running "pkg-config --libs --cflags samplerate" failed: FileNotFoundError(2, '系统找不到指定的文件。', None, 2, None)
      Info: libaubio was not installed or built locally with waf, adding src/
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for aubio
  Running setup.py clean for aubio
Failed to build aubio
ERROR: Could not build wheels for aubio, which is required to install pyproject.toml-based projects
 

 


参考:

 1 安装aubio:

Installing aubio — aubio 0.4.9 documentation

@python

Installing aubio for Python — aubio 0.4.9 documentation

2 下载aubio

https://aubio.org/download

3 Python的包安装管理手册: PyPA的基本使用:

PYPI下的aubio项目地址:

aubio · PyPI

Installing Packages - Python Packaging User Guide

4 aubio 开源仓库:

https://github.com/aubio/aubio

@python

aubio/python at master · aubio/aubio · GitHub

各个版本列表:

Index of /pub

aubio

=====

aubio is a collection of tools for music and audio analysis.

This package integrates the aubio library with [NumPy] to provide a set of

efficient tools to process and analyse audio signals, including:

- read audio from any media file, including videos and remote streams

- high quality phase vocoder, spectral filterbanks, and linear filters

- Mel-Frequency Cepstrum Coefficients and standard spectral descriptors

- detection of note attacks (onset)

- pitch tracking (fundamental frequency estimation)

- beat detection and tempo tracking

aubio works with both Python 2 and Python 3.

Links

-----

- [module documentation][doc_python]

- [installation instructions][doc_python_install]

- [aubio manual][manual]

- [aubio homepage][homepage]

- [issue tracker][bugtracker]

Demos

-----

Some examples are available in the [`python/demos` folder][demos_dir]. Each

script is a command line program which accepts one ore more argument.

**Notes**: installing additional modules is required to run some of the demos.

### Analysis

- `demo_source.py` uses aubio to read audio samples from media files

- `demo_onset_plot.py` detects attacks in a sound file and plots the results

  using [matplotlib]

- `demo_pitch.py` looks for fundamental frequency in a sound file and plots the

  results using [matplotlib]

- `demo_spectrogram.py`, `demo_specdesc.py`, `demo_mfcc.py` for spectral

  analysis.

### Real-time

- `demo_pyaudio.py` and `demo_tapthebeat.py` use [pyaudio]

- `demo_pysoundcard_play.py`, `demo_pysoundcard.py` use [PySoundCard]

- `demo_alsa.py` uses [pyalsaaudio]

### Others

- `demo_timestretch.py` can change the duration of an input file and write the

  new sound to disk,

- `demo_wav2midi.py` detects the notes in a file and uses [mido] to write the

  results into a MIDI file

### Example

Use `demo_timestretch_online.py` to slow down `loop.wav`, write the results in

`stretched_loop.wav`:

    $ python demo_timestretch_online.py loop.wav stretched_loop.wav 0.92

Built with

----------

The core of aubio is written in C for portability and speed. In addition to

[NumPy], aubio can be optionally built to use one or more of the following

libraries:

- media file reading:

    - [ffmpeg] / [avcodec] to decode and read audio from almost any format,

    - [libsndfile] to read audio from uncompressed sound files,

    - [libsamplerate] to re-sample audio signals,

    - [CoreAudio] to read all media formats supported by macOS, iOS, and tvOS.

- hardware acceleration:

    - [Atlas] and [Blas], for accelerated vector and matrix computations,

    - [fftw3], to compute fast Fourier Transforms of any size,

    - [Accelerate] for accelerated FFT and matrix computations (macOS/iOS),

    - [Intel IPP], accelerated vector computation and FFT implementation.

[ffmpeg]: https://ffmpeg.org

[avcodec]: https://libav.org

[libsndfile]: http://www.mega-nerd.com/libsndfile/

[libsamplerate]: http://www.mega-nerd.com/SRC/

[CoreAudio]: https://developer.apple.com/reference/coreaudio

[Atlas]: http://math-atlas.sourceforge.net/

[Blas]: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms

[fftw3]: http://fftw.org

[Accelerate]: https://developer.apple.com/reference/accelerate

[Intel IPP]: https://software.intel.com/en-us/intel-ipp

[demos_dir]:https://github.com/aubio/aubio/tree/master/python/demos

[pyaudio]:https://people.csail.mit.edu/hubert/pyaudio/

[PySoundCard]:https://github.com/bastibe/PySoundCard

[pyalsaaudio]:https://larsimmisch.github.io/pyalsaaudio/

[mido]:https://mido.readthedocs.io

[manual]: https://aubio.org/manual/latest/

[doc_python]: https://aubio.org/manual/latest/python.html

[doc_python_install]: https://aubio.org/manual/latest/python_module.html

[homepage]: https://aubio.org

[NumPy]: https://www.numpy.org

[bugtracker]: https://github.com/aubio/aubio/issues

[matplotlib]:https://matplotlib.org/


网站公告

今日签到

点亮在社区的每一天
去签到