annotate README.rst @ 151:5a6b8f4be9b9 tracks tip

Docs
author Chris Cannam
date Fri, 21 Apr 2017 14:33:57 +0100
parents f798cda1007f
children
rev   line source
Chris@117 1
Chris@117 2 Python Vamp plugin host
Chris@117 3 =======================
Chris@117 4
Chris@126 5 This module allows Python code to load and use native-code Vamp
Chris@126 6 plugins (http://vamp-plugins.org) for audio feature analysis.
Chris@117 7
Chris@126 8 The module consists of a native-code extension ("vampyhost") that
Chris@126 9 provides a low-level wrapper for the Vamp plugin SDK, along with a
Chris@126 10 Python wrapper ("vamp") that provides a higher-level abstraction.
Chris@117 11
Chris@126 12 No code for loading audio files is included; you'll need to use some
Chris@126 13 other module for that. This code expects to receive decoded audio data
Chris@126 14 of one or more channels, either as a series of frames or as a single
Chris@126 15 whole buffer.
Chris@117 16
Chris@123 17 Written by Chris Cannam and George Fazekas at the Centre for Digital
Chris@123 18 Music, Queen Mary University of London. Copyright 2008-2015 Queen
Chris@123 19 Mary, University of London. Refer to COPYING.rst for licence details.
Chris@123 20
Chris@123 21 See home page at https://code.soundsoftware.ac.uk/projects/vampy-host
Chris@123 22 for more details.
Chris@123 23
Chris@117 24
Chris@117 25 A simple example
Chris@117 26 ----------------
Chris@117 27
Chris@126 28 Using librosa (http://bmcfee.github.io/librosa/) to read an audio
Chris@126 29 file, and the NNLS Chroma Vamp plugin
Chris@126 30 (https://code.soundsoftware.ac.uk/projects/nnls-chroma/) for
Chris@126 31 analysis::
Chris@117 32
Chris@123 33 >>> import vamp
Chris@123 34 >>> import librosa
Chris@123 35 >>> data, rate = librosa.load("example.wav")
Chris@126 36 >>> chroma = vamp.collect(data, rate, "nnls-chroma:nnls-chroma")
Chris@126 37 >>> chroma
Chris@123 38 {'matrix': ( 0.092879819, array([[ 61.0532608 , 60.27478409, 59.3938446 , ..., 182.13394165,
Chris@123 39 42.40084457, 116.55457306],
Chris@123 40 [ 68.8901825 , 63.98115921, 60.77633667, ..., 245.88218689,
Chris@123 41 68.51251984, 164.70120239],
Chris@123 42 [ 58.59794617, 50.3429184 , 45.44804764, ..., 258.02362061,
Chris@123 43 83.95749664, 179.91200256],
Chris@123 44 ...,
Chris@123 45 [ 0. , 0. , 0. , ..., 0. ,
Chris@123 46 0. , 0. ],
Chris@123 47 [ 0. , 0. , 0. , ..., 0. ,
Chris@123 48 0. , 0. ],
Chris@123 49 [ 0. , 0. , 0. , ..., 0. ,
Chris@123 50 0. , 0. ]], dtype=float32))}
Chris@126 51 >>> stepsize, chromadata = chroma["matrix"]
Chris@123 52 >>> import matplotlib.pyplot as plt
Chris@123 53 >>> plt.imshow(chromadata)
Chris@123 54 <matplotlib.image.AxesImage object at 0x7fe9e0043fd0>
Chris@123 55 >>> plt.show()
Chris@117 56
Chris@126 57 And a pitch-chroma plot appears.
Chris@117 58
Chris@126 59
Chris@126 60 High-level interface (vamp)
Chris@126 61 ---------------------------
Chris@126 62
Chris@126 63 This module contains three sorts of function:
Chris@126 64
Chris@132 65 1. Basic info and lookup functions
Chris@132 66 """"""""""""""""""""""""""""""""""
Chris@126 67
Chris@129 68 * ``vamp.list_plugins``
Chris@129 69 * ``vamp.get_outputs_of``
Chris@129 70 * ``vamp.get_category_of``
Chris@126 71
Chris@129 72 These retrieve the installed plugin keys and get basic information
Chris@129 73 about each plugin. (For more detailed information, load a plugin
Chris@129 74 and inspect it using the low-level interface described below.)
Chris@129 75
Chris@132 76 2. Process functions
Chris@132 77 """"""""""""""""""""
Chris@129 78
Chris@129 79 * ``vamp.process_audio``
Chris@129 80 * ``vamp.process_frames``
Chris@129 81 * ``vamp.process_audio_multiple_outputs``
Chris@129 82 * ``vamp.process_frames_multiple_outputs``
Chris@126 83
Chris@126 84 These accept audio input, and produce output in the form of a list
Chris@126 85 of feature sets structured similarly to those in the C++ Vamp
Chris@129 86 plugin SDK. The plugin to be used is specified by its key (the
Chris@129 87 identifier as returned by ``vamp.list_plugins``). A dictionary of
Chris@129 88 plugin parameter settings may optionally be supplied.
Chris@126 89
Chris@126 90 The ``_audio`` versions take a single (presumably long) array of
Chris@126 91 audio samples as input, and chop it into frames according to the
Chris@126 92 plugin's preferred step and block sizes. The ``_frames`` versions
Chris@126 93 instead accept an enumerable sequence of audio frame arrays.
Chris@126 94
Chris@132 95 3. The process-and-collect function
Chris@132 96 """""""""""""""""""""""""""""""""""
Chris@132 97
Chris@129 98 * ``vamp.collect``
Chris@126 99
Chris@126 100 This accepts a single array of audio samples as input, and returns
Chris@126 101 an output structure that reflects the underlying structure of the
Chris@126 102 feature output (depending on whether it is a curve, grid, etc). The
Chris@129 103 plugin to be used is specified by its key. A dictionary of plugin
Chris@129 104 parameter settings may optionally be supplied.
Chris@126 105
Chris@126 106 The ``collect`` function processes the whole input before returning
Chris@126 107 anything; if you need to supply a streamed input, or retrieve
Chris@126 108 results as they are calculated, then you must use one of the
Chris@126 109 ``process`` functions (above) or else the low-level interface
Chris@126 110 (below).
Chris@126 111
Chris@126 112
Chris@126 113 Low-level interface (vampyhost)
Chris@126 114 -------------------------------
Chris@126 115
Chris@126 116 This extension contains facilities that operate on Vamp plugins in a
Chris@126 117 way analogous to the existing C++ Vamp Host SDK: ``list_plugins``,
Chris@126 118 ``get_plugin_path``, ``get_category_of``, ``get_library_for``,
Chris@126 119 ``get_outputs_of``, ``load_plugin``, and a utility function
Chris@126 120 ``frame_to_realtime``.
Chris@126 121
Chris@126 122 Calling ``load_plugin`` gets you a ``vampyhost.Plugin`` object, which
Chris@126 123 then exposes all of the methods found in the Vamp SDK Plugin class.
Chris@126 124
Chris@126 125 (Note that methods wrapped directly from the Vamp SDK are named using
Chris@126 126 camelCase, so as to match the names found in the C++ SDK. Elsewhere
Chris@126 127 this module follows Python PEP8 naming.)
Chris@126 128
Chris@126 129 See the individual module and function documentation for further
Chris@126 130 details.
Chris@126 131