From d44763f5633fb9ef8cbf72a4652c9a87a6416b55 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 27 Aug 2016 00:39:56 +0200 Subject: [PATCH] doc/python_module.rst: add demo_source_simple.py --- doc/python_module.rst | 34 +++++++++++++++++----------------- python/demos/demo_source_simple.py | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 python/demos/demo_source_simple.py diff --git a/doc/python_module.rst b/doc/python_module.rst index 3568ba88..17819b34 100644 --- a/doc/python_module.rst +++ b/doc/python_module.rst @@ -1,9 +1,15 @@ +.. _python: + Python module ============= +The aubio extension for Python is available for Python 2.7 and Python 3. + Installing aubio with pip ------------------------- +aubio can now be installed using ``pip`` and ``easy_install``. + .. code-block:: bash $ pip install aubio @@ -25,31 +31,25 @@ Using aubio in python Once you have python-aubio installed, you should be able to run ``python -c "import aubio"``. -A very simple example -..................... +A simple example +................ -Here is a very simple script -to read all the samples from a media file: +Here is a :download:`simple script <../python/demos/demo_source_simple.py>` +that reads all the samples from a media file: -.. code-block:: python - - #! /usr/bin/env python - import aubio - - s = aubio.source(sys.argv[1], 0, 256) - while True: - samples, read = s() - #print(samples) - if read < 256: break +.. literalinclude:: ../python/demos/demo_source_simple.py + :language: python Filtering an input sound file ............................. -Here is a more complete example, `demo_filter.py`_. This files executes the following: +Here is a more complete example, :download:`demo_filter.py +<../python/demos/demo_filter.py>`. This files executes the following: * read an input media file (``aubio.source``) -* filter it using an A-weighting filter (``aubio.digital_filter``) +* filter it using an `A-weighting `_ + filter (``aubio.digital_filter``) * write result to a new file (``aubio.sink``) @@ -67,7 +67,7 @@ Python tests A number of `python tests`_ are provided. To run them, use ``python/tests/run_all_tests``. -.. _python tests folder: https://github.com/aubio/aubio/blob/master/python/tests .. _python demos folder: https://github.com/aubio/aubio/blob/master/python/demos .. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py +.. _python tests: https://github.com/aubio/aubio/blob/master/python/tests diff --git a/python/demos/demo_source_simple.py b/python/demos/demo_source_simple.py new file mode 100644 index 00000000..e9660327 --- /dev/null +++ b/python/demos/demo_source_simple.py @@ -0,0 +1,16 @@ +#! /usr/bin/env python +import sys, aubio + +samplerate = 0 # use original source samplerate +hop_size = 256 # number of frames to read in one block +s = aubio.source(sys.argv[1], samplerate, hop_size) +total_frames = 0 + +while True: # reading loop + samples, read = s() + total_frames += read + if read < hop_size: break # end of file reached + +fmt_string = "read {:d} frames at {:d}Hz from {:s}" +print (fmt_string.format(total_frames, s.samplerate, sys.argv[1])) + -- 2.11.0