ref: d44763f5633fb9ef8cbf72a4652c9a87a6416b55
parent: 2f965e2f8a57966608e7328cd6bebb0459baf617
author: Paul Brossier <piem@piem.org>
date: Fri Aug 26 20:39:56 EDT 2016
doc/python_module.rst: add demo_source_simple.py
--- 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 @@
Once you have python-aubio installed, you should be able to run ``python -c
"import aubio"``.
-A very simple example
-.....................
-
-Here is a very simple script
-to read all the samples from a media file:
+A simple example
+................
-.. code-block:: python
+Here is a :download:`simple script <../python/demos/demo_source_simple.py>`
+that reads all the samples from a media file:
- #! /usr/bin/env python
- import aubio
+.. literalinclude:: ../python/demos/demo_source_simple.py
+ :language: python
- s = aubio.source(sys.argv[1], 0, 256)
- while True:
- samples, read = s()
- #print(samples)
- if read < 256: break
-
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 <https://en.wikipedia.org/wiki/A-weighting>`_
+ filter (``aubio.digital_filter``)
* write result to a new file (``aubio.sink``)
@@ -67,7 +67,7 @@
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
--- /dev/null
+++ b/python/demos/demo_source_simple.py
@@ -1,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]))
+