Showing the changes to python (2 of 15 files). Show all
Unified · Split
| @@ -1,105 +1,109 @@ | |||
| 1 | Python aubio module | 1 | aubio |
| 2 | =================== | 2 | ===== |
| 3 | 3 | ||
| 4 | This module wraps the aubio library for Python using the numpy module. | 4 | aubio is a collection of tools for music and audio analysis. |
| 5 | 5 | ||
| 6 | Using the Python aubio module | 6 | This package integrates the aubio library with [NumPy] to provide a set of |
| 7 | ----------------------------- | 7 | efficient tools to process and analyse audio signals, including: |
| 8 | 8 | ||
| 9 | After installing python-aubio, you will be able to import the aubio module: | 9 | - read audio from any media file, including videos and remote streams |
| 10 | - high quality phase vocoder, spectral filterbanks, and linear filters | ||
| 11 | - Mel-Frequency Cepstrum Coefficients and standard spectral descriptors | ||
| 12 | - detection of note attacks (onset) | ||
| 13 | - pitch tracking (fundamental frequency estimation) | ||
| 14 | - beat detection and tempo tracking | ||
| 10 | 15 | ||
| 11 | $ python | 16 | aubio works with both Python 2 and Python 3. |
| 12 | [...] | ||
| 13 | >>> import aubio | ||
| 14 | >>> help(aubio.miditofreq) | ||
| 15 | 17 | ||
| 16 | Finding some inspiration | 18 | Links |
| 17 | ------------------------ | 19 | ----- |
| 18 | 20 | ||
| 19 | Some examples are available in the `python/demos` directory. These scripts are | 21 | - [module documentation][doc_python] |
| 20 | small programs written in python and using python-aubio. | 22 | - [installation instructions][doc_python_install] |
| 23 | - [aubio manual][manual] | ||
| 24 | - [aubio homepage][homepage] | ||
| 25 | - [issue tracker][bugtracker] | ||
| 21 | 26 | ||
| 22 | For instance, `demo_source.py` reads a media file. | 27 | Demos |
| 28 | ----- | ||
| 23 | 29 | ||
| 24 | $ ./python/demos/demo_source.py /path/to/sound/sample.wav | 30 | Some examples are available in the [`python/demos`][demos_dir] folder. Each |
| 31 | script is a command line program which accepts one ore more argument. | ||
| 25 | 32 | ||
| 26 | and `demo_timestretch_online.py` stretches the original file into a new one: | 33 | **Notes**: installing additional modules is required to run some of the demos. |
| 27 | 34 | ||
| 28 | $ ./python/demo/demo_timestretch_online.py loop.wav stretched_loop.wav 0.92` | 35 | ### Analysis |
| 29 | 36 | ||
| 30 | Note: you might need to install additional modules to run some of the demos. | 37 | - `demo_source.py` uses aubio to read audio samples from media files |
| 31 | Some demos use [matplotlib](http://matplotlib.org/) to draw plots, others use | 38 | - `demo_onset_plot.py` detects attacks in a sound file and plots the results |
| 32 | [PySoundCard](https://github.com/bastibe/PySoundCard) to play and record | 39 | using [matplotlib] |
| 33 | sounds. | 40 | - `demo_pitch.py` looks for fundamental frequency in a sound file and plots the |
| 41 | results using [matplotlib] | ||
| 42 | - `demo_spectrogram.py`, `demo_specdesc.py`, `demo_mfcc.py` for spectral | ||
| 43 | analysis. | ||
| 34 | 44 | ||
| 35 | Testing the Python module | 45 | ### Real-time |
| 36 | ------------------------- | ||
| 37 | 46 | ||
| 38 | Python tests are in `python/tests` and use [pytest]. | 47 | - `demo_pyaudio.py` and `demo_tapthebeat.py` use [pyaudio] |
| 48 | - `demo_pysoundcard_play.py`, `demo_pysoundcard.py` use [PySoundCard] | ||
| 49 | - `demo_alsa.py` uses [pyalsaaudio] | ||
| 39 | 50 | ||
| 40 | To run the all the python tests: | 51 | ### Others |
| 41 | 52 | ||
| 42 | $ cd aubio | 53 | - `demo_timestretch.py` can change the duration of an input file and write the |
| 43 | $ pytest | 54 | new sound to disk, |
| 55 | - `demo_wav2midi.py` detects the notes in a file and uses [mido] to write the | ||
| 56 | results into a MIDI file | ||
| 44 | 57 | ||
| 45 | Each test script can also be called one at a time. For instance: | 58 | ### Example |
| 46 | 59 | ||
| 47 | $ pytest -v python/tests/test_note2midi.py | 60 | Use `demo_timestretch_online.py` to slow down `loop.wav`, write the results in |
| 61 | `stretched_loop.wav`: | ||
| 48 | 62 | ||
| 49 | [pytest]: https://pytest.org | 63 | $ python demo_timestretch_online.py loop.wav stretched_loop.wav 0.92 |
| 50 | 64 | ||
| 51 | Install in a virtualenv | 65 | Built with |
| 52 | ----------------------- | ||
| 53 | |||
| 54 | You should be able to install python-aubio directly from the top source | ||
| 55 | directory of aubio. | ||
| 56 | |||
| 57 | First, create a virtualenv to hold the required python module: | ||
| 58 | |||
| 59 | $ virtualenv pyaubio | ||
| 60 | $ source pyaubio/bin/activate | ||
| 61 | |||
| 62 | Now install and build the python extension using: | ||
| 63 | |||
| 64 | $ pip install . | ||
| 65 | |||
| 66 | Install requirements | ||
| 67 | -------------------- | ||
| 68 | |||
| 69 | Before compiling this module, you must have compiled libaubio. | ||
| 70 | |||
| 71 | A simple way to do this is with pip: | ||
| 72 | |||
| 73 | $ pip install -r requirements.txt | ||
| 74 | |||
| 75 | For more information about how this module works, please refer to the [Python/C | ||
| 76 | API Reference Manual] (http://docs.python.org/c-api/index.html) and the | ||
| 77 | [Numpy/C API Reference](http://docs.scipy.org/doc/numpy/reference/c-api.html). | ||
| 78 | |||
| 79 | Compiling python aubio | ||
| 80 | ---------------------- | ||
| 81 | |||
| 82 | To build the aubio Python module, run the following command from the top source | ||
| 83 | directory of aubio: | ||
| 84 | |||
| 85 | $ ./setup.py build | ||
| 86 | |||
| 87 | Note: if libaubio was previously built using waf, the script will use it. | ||
| 88 | Otherwise, the entire library will be built inside the python extension. | ||
| 89 | |||
| 90 | To find out more about `setup.py` options: | ||
| 91 | |||
| 92 | $ ./setup.py --help | ||
| 93 | |||
| 94 | Installing | ||
| 95 | ---------- | 66 | ---------- |
| 96 | 67 | ||
| 97 | To install the Python module: | 68 | The core of aubio is written in C for portability and speed. In addition to |
| 98 | 69 | [NumPy], aubio can be optionally built to use one or more of the following | |
| 99 | $ ./setup.py install | 70 | libraries: |
| 100 | 71 | ||
| 101 | Alternatively, you may want to use the Python module without installing it by | 72 | - media file reading: |
| 102 | setting your PYTHONPATH, for instance as follows: | 73 | |
| 103 | 74 | - [ffmpeg] / [avcodec] to decode and read audio from almost any format, | |
| 104 | $ export PYTHONPATH=$PYTHONPATH:$PWD/`ls -rtd build/lib.* | head -1`:$PWD/tests | 75 | - [libsndfile] to read audio from uncompressed sound files, |
| 105 | 76 | - [libsamplerate] to re-sample audio signals, | |
| 77 | - [CoreAudio] to read all media formats supported by macOS, iOS, and tvOS. | ||
| 78 | |||
| 79 | - hardware acceleration: | ||
| 80 | |||
| 81 | - [Atlas] and [Blas], for accelerated vector and matrix computations, | ||
| 82 | - [fftw3], to compute fast Fourier Transforms of any size, | ||
| 83 | - [Accelerate] for accelerated FFT and matrix computations (macOS/iOS), | ||
| 84 | - [Intel IPP], accelerated vector computation and FFT implementation. | ||
| 85 | |||
| 86 | [ffmpeg]: https://ffmpeg.org | ||
| 87 | [avcodec]: https://libav.org | ||
| 88 | [libsndfile]: http://www.mega-nerd.com/libsndfile/ | ||
| 89 | [libsamplerate]: http://www.mega-nerd.com/SRC/ | ||
| 90 | [CoreAudio]: https://developer.apple.com/reference/coreaudio | ||
| 91 | [Atlas]: http://math-atlas.sourceforge.net/ | ||
| 92 | [Blas]: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms | ||
| 93 | [fftw3]: http://fftw.org | ||
| 94 | [Accelerate]: https://developer.apple.com/reference/accelerate | ||
| 95 | [Intel IPP]: https://software.intel.com/en-us/intel-ipp | ||
| 96 | |||
| 97 | [demos_dir]:https://github.com/aubio/aubio/tree/master/python/demos | ||
| 98 | [pyaudio]:https://people.csail.mit.edu/hubert/pyaudio/ | ||
| 99 | [PySoundCard]:https://github.com/bastibe/PySoundCard | ||
| 100 | [pyalsaaudio]:https://larsimmisch.github.io/pyalsaaudio/ | ||
| 101 | [mido]:https://mido.readthedocs.io | ||
| 102 | |||
| 103 | [manual]: https://aubio.org/manual/latest/ | ||
| 104 | [doc_python]: https://aubio.org/manual/latest/python.html | ||
| 105 | [doc_python_install]: https://aubio.org/manual/latest/python_module.html | ||
| 106 | [homepage]: https://aubio.org | ||
| 107 | [NumPy]: https://www.numpy.org | ||
| 108 | [bugtracker]: https://github.com/aubio/aubio/issues | ||
| 109 | [matplotlib]:https://matplotlib.org/ | ||
| @@ -8,7 +8,7 @@ import unittest · 7 unmodified lines | |||
| 8 | import aubio | 8 | import aubio |
| 9 | import numpy as np | 9 | import numpy as np |
| 10 | from numpy.testing import assert_equal | 10 | from numpy.testing import assert_equal |
| 11 | from utils import get_tmp_sink_path | 11 | from .utils import get_tmp_sink_path |
| 12 | 12 | ||
| 13 | class aubio_source_test_case(unittest.TestCase): | 13 | class aubio_source_test_case(unittest.TestCase): |
| 14 | 14 | ||