Wiki » History » Version 2

Chris Cannam, 2012-07-17 06:27 PM

1 1 Chris Cannam
h1. About Sonic Annotator
2 1 Chris Cannam
3 1 Chris Cannam
Sonic Annotator is a batch tool for feature extraction and annotation of audio files.  The audio to be processed can be on the local filesystem or available or over http or ftp.  It will run available "Vamp plugins":http://vamp-plugins.org/ on a wide range of audio file types, and can write the results in a selection of formats.
4 1 Chris Cannam
5 1 Chris Cannam
h2. A Quick Tutorial
6 1 Chris Cannam
7 1 Chris Cannam
To use Sonic Annotator, you need to tell it three things: what audio files to extract features from; what features to extract; and how and where to write the results.  You can also optionally tell it to summarise the features.
8 1 Chris Cannam
9 1 Chris Cannam
h3. 1. What audio files to extract features from
10 1 Chris Cannam
11 1 Chris Cannam
Sonic Annotator accepts a list of audio files on the command line. Any argument that is not understood as a supported command-line option will be taken to be the name of an audio file.  Any number of files may be listed.
12 1 Chris Cannam
13 1 Chris Cannam
Several common audio file formats are supported, including MP3, Ogg, and a number of PCM formats such as WAV and AIFF.  AAC is supported on OS/X only, and only if not DRM protected.  WMA is not supported.
14 1 Chris Cannam
15 1 Chris Cannam
File paths do not have to be local; you can also provide remote HTTP or FTP URLs for Sonic Annotator to retrieve.
16 1 Chris Cannam
17 1 Chris Cannam
Sonic Annotator also accepts the names of playlist files (with <code>.m3u</code> extension) and will process every file found in the playlist.
18 1 Chris Cannam
19 1 Chris Cannam
A limitation of the current version of Sonic Annotator on Windows is that it requires forward slash as the path separator ("/") instead of backslash ("\") to avoid writing incorrect URLs into the output in RDF writer mode.  For example, @C:/audio/testfile.wav@.
20 1 Chris Cannam
21 1 Chris Cannam
Finally, you can provide a local directory path instead of a file, together with the @-r@ (recursive) option, for Sonic Annotator to process every audio file found in that directory or any of its subdirectories.
22 1 Chris Cannam
23 1 Chris Cannam
h3. 2. What features to extract
24 1 Chris Cannam
25 1 Chris Cannam
Sonic Annotator applies "transforms" to its input audio files, where a transform (in this terminology) consists of a Vamp plugin together with a certain set of parameters and a specified execution context: step and block size, sample rate, etc.
26 1 Chris Cannam
27 1 Chris Cannam
To use a particular transform, specify its filename on the command line with the <code>-t</code> option.
28 1 Chris Cannam
29 2 Chris Cannam
Transforms are usually described in RDF, following the transform part of the "Vamp plugin ontology":http://purl.org/ontology/vamp/.  A Transform may use any Vamp plugin that is currently installed and available on the system.  You can obtain a list of available plugin outputs by running Sonic Annotator with the @-l@ option, and you can obtain a skeleton transform description for one of these plugins with the @-s@ option.
30 1 Chris Cannam
31 1 Chris Cannam
For example, if the example plugins from the Vamp plugin SDK are available and no other plugins are installed, you might expect to see this listing from the @-l@ option:
32 1 Chris Cannam
33 1 Chris Cannam
<pre>
34 1 Chris Cannam
  $ sonic-annotator -l
35 1 Chris Cannam
  vamp:vamp-example-plugins:amplitudefollower:amplitude
36 1 Chris Cannam
  vamp:vamp-example-plugins:fixedtempo:acf
37 1 Chris Cannam
  vamp:vamp-example-plugins:fixedtempo:detectionfunction
38 1 Chris Cannam
  vamp:vamp-example-plugins:fixedtempo:filtered_acf
39 1 Chris Cannam
  vamp:vamp-example-plugins:fixedtempo:tempo
40 1 Chris Cannam
  vamp:vamp-example-plugins:fixedtempo:candidates
41 1 Chris Cannam
  vamp:vamp-example-plugins:percussiononsets:detectionfunction
42 1 Chris Cannam
  vamp:vamp-example-plugins:percussiononsets:onsets
43 1 Chris Cannam
  vamp:vamp-example-plugins:powerspectrum:powerspectrum
44 1 Chris Cannam
  vamp:vamp-example-plugins:spectralcentroid:linearcentroid
45 1 Chris Cannam
  vamp:vamp-example-plugins:spectralcentroid:logcentroid
46 1 Chris Cannam
  vamp:vamp-example-plugins:zerocrossing:counts
47 1 Chris Cannam
  vamp:vamp-example-plugins:zerocrossing:zerocrossings
48 1 Chris Cannam
  $
49 1 Chris Cannam
</pre>
50 1 Chris Cannam
51 1 Chris Cannam
and this from @-s@:
52 1 Chris Cannam
53 1 Chris Cannam
<pre>
54 1 Chris Cannam
  $ sonic-annotator -s vamp:vamp-example-plugins:fixedtempo:tempo
55 1 Chris Cannam
  @prefix xsd:      &lt;http://www.w3.org/2001/XMLSchema#&gt; .
56 1 Chris Cannam
  @prefix vamp:     &lt;http://purl.org/ontology/vamp/&gt; .
57 1 Chris Cannam
  @prefix :         &lt;#&gt; .
58 1 Chris Cannam
59 1 Chris Cannam
  :transform a vamp:Transform ;
60 1 Chris Cannam
      vamp:plugin &lt;http://vamp-plugins.org/rdf/plugins/vamp-example-plugins#fixedtempo&gt; ;
61 1 Chris Cannam
      vamp:step_size "64"^^xsd:int ; 
62 1 Chris Cannam
63 1 Chris Cannam
      vamp:block_size "256"^^xsd:int ; 
64 1 Chris Cannam
      vamp:parameter_binding [
65 1 Chris Cannam
          vamp:parameter [ vamp:identifier "maxbpm" ] ;
66 1 Chris Cannam
          vamp:value "190"^^xsd:float ;
67 1 Chris Cannam
      ] ;
68 1 Chris Cannam
      vamp:parameter_binding [
69 1 Chris Cannam
          vamp:parameter [ vamp:identifier "maxdflen" ] ;
70 1 Chris Cannam
          vamp:value "10"^^xsd:float ;
71 1 Chris Cannam
      ] ;
72 1 Chris Cannam
      vamp:parameter_binding [
73 1 Chris Cannam
          vamp:parameter [ vamp:identifier "minbpm" ] ;
74 1 Chris Cannam
          vamp:value "50"^^xsd:float ;
75 1 Chris Cannam
      ] ;
76 1 Chris Cannam
      vamp:output &lt;http://vamp-plugins.org/rdf/plugins/vamp-example-plugins#fixedtempo_output_tempo&gt; .
77 1 Chris Cannam
  $
78 1 Chris Cannam
</pre>
79 1 Chris Cannam
80 1 Chris Cannam
The output of this example is an RDF/Turtle document describing the default settings for the Tempo output of the Fixed Tempo Estimator plugin in the Vamp plugin SDK.
81 1 Chris Cannam
82 1 Chris Cannam
(The exact format of the RDF printed may differ -- e.g. if the plugin's RDF description is not installed and so its "home" URI is not known -- but the result should be functionally equivalent to this.)
83 1 Chris Cannam
84 1 Chris Cannam
You can then run this transform by saving the RDF to a file and specifying that file with @-t@:
85 1 Chris Cannam
86 1 Chris Cannam
<pre>
87 1 Chris Cannam
  $ sonic-annotator -s vamp:vamp-example-plugins:fixedtempo:tempo &gt; test.n3
88 1 Chris Cannam
  $ sonic-annotator -t test.n3 audio.wav -w csv --csv-stdout
89 1 Chris Cannam
  (... logging output on stderr, then ...)
90 1 Chris Cannam
  "audio.wav",0.002902494,5.196916099,68.7916,"68.8 bpm"
91 1 Chris Cannam
  $
92 1 Chris Cannam
</pre>
93 1 Chris Cannam
94 1 Chris Cannam
The single line of output above consists of the audio file name, the timestamp and duration for a single feature, the value of that feature (the estimated tempo of the given region of time from that file, in bpm -- the plugin in question performs a single tempo estimation and nothing else) and the feature's label.
95 1 Chris Cannam
96 1 Chris Cannam
A quicker way to achieve the above is to use the @-d@ (default) option to tell Sonic Annotator to use directly the default configuration for a named transform:
97 1 Chris Cannam
98 1 Chris Cannam
<pre>
99 1 Chris Cannam
  $ sonic-annotator -d vamp:vamp-example-plugins:fixedtempo:tempo audio.wav -w csv --csv-stdout
100 1 Chris Cannam
  (... some log output on stderr, then ...)
101 1 Chris Cannam
  "audio.wav",0.002902494,5.196916099,68.7916,"68.8 bpm"
102 1 Chris Cannam
  $
103 1 Chris Cannam
</pre>
104 1 Chris Cannam
105 1 Chris Cannam
Although handy for experimentation, the @-d@ option is inadvisable in any "production" situation because the plugin configuration is not guaranteed to be the same each time (for example if an updated version of a plugin changes some of its defaults).  It's better to save a well-defined transform to file and refer to that, even if it is simply the transform created by the skeleton option.
106 1 Chris Cannam
107 1 Chris Cannam
To run more than one transform on the same audio files, just put more than one set of transform RDF descriptions in the same file, or give the @-t@ option more than once with separate transform description files.  Remember that if you want to specify more than one transform in the same file, they will need to have distinct URIs (that is, the @:transform@ part of the example above, which may be any arbitrary name, must be distinct for each described transform).
108 1 Chris Cannam
109 1 Chris Cannam
h3. 3. How and where to write the results
110 1 Chris Cannam
111 1 Chris Cannam
Sonic Annotator supports various different output modules (and it is fairly easy for the developer to add new ones).  You have to choose at least one output module; use the @-w@ (writer) option to do so.  Each module has its own set of parameters which can be adjusted on the
112 1 Chris Cannam
command line, as well as its own default rules about where to write the results.
113 1 Chris Cannam
114 1 Chris Cannam
The following writers are currently supported.  (Others exist, but are not properly implemented or not supported.)
115 1 Chris Cannam
116 1 Chris Cannam
h3. csv
117 1 Chris Cannam
118 1 Chris Cannam
Writes the results into comma-separated data files.
119 1 Chris Cannam
120 1 Chris Cannam
One file is created for each transform applied to each input audio  file, named after the input audio file and transform name with <code>.csv</code>   suffix and ":" replaced by "_" throughout, placed in the same   directory as the audio file.
121 1 Chris Cannam
122 1 Chris Cannam
To instruct Sonic Annotator to place the output files in another   location, use <code>--csv-basedir</code> with a directory name.
123 1 Chris Cannam
124 1 Chris Cannam
To write a single file with all data in it, use <code>--csv-one-file</code>.
125 1 Chris Cannam
126 1 Chris Cannam
To write all data to standard output instead of to a file, use <code>--csv-stdout</code>.
127 1 Chris Cannam
128 1 Chris Cannam
Sonic Annotator will not write to an output file that already   exists.  If you want to make it do this, use <code>--csv-force to</code>   overwrite or <code>--csv-append</code> to append to it.
129 1 Chris Cannam
130 1 Chris Cannam
The data generated consists of one line for each result feature,   containing the feature timestamp, feature duration if present, all   of the feature's bin values in order, followed by the feature's   label if present.  If the <code>--csv-one-file</code> or <code>--csv-stdout</code> option is   specified, then an additional column will appear before any of the   above, containing the audio file name from which the feature was   extracted, if it differs from that of the previous row.
131 1 Chris Cannam
 
132 1 Chris Cannam
The default column separator is a comma; you can specify   a different one with the <code>--csv-separator</code> option.
133 1 Chris Cannam
134 1 Chris Cannam
h3. rdf
135 1 Chris Cannam
136 2 Chris Cannam
Writes the results into RDF/Turtle documents following the "Audio Features ontology":http://purl.org/ontology/af/.
137 1 Chris Cannam
138 1 Chris Cannam
One file is created for each input audio file containing the   features extracted by all transforms applied to that file, named   after the input audio file with <code>.n3</code> extension, placed in the same    directory as the audio file.
139 1 Chris Cannam
140 1 Chris Cannam
To instruct Sonic Annotator to place the output files in another   location, use <code>--rdf-basedir</code> with a directory name.
141 1 Chris Cannam
142 1 Chris Cannam
To write a single file with all data (from all input audio files)   in it, use <code>--rdf-one-file</code>.
143 1 Chris Cannam
144 1 Chris Cannam
To write one file for each transform applied to each input audio   file, named after the input audio file and transform name with <code>.n3</code>   suffix and ":" replaced by "_" throughout, use <code>--rdf-many-files</code>.
145 1 Chris Cannam
146 1 Chris Cannam
To write all data to standard output instead of to a file, use <code>--rdf-stdout</code>.
147 1 Chris Cannam
148 1 Chris Cannam
Sonic Annotator will not write to an output file that already   exists.  If you want to make it do this, use <code>--rdf-force</code> to   overwrite or <code>--rdf-append</code> to append to it.
149 1 Chris Cannam
150 1 Chris Cannam
Sonic Annotator will use plugin description RDF if available to   enhance its output (for example identifying note onset times as   note onset times, if the plugin's RDF says that is what it   produces, rather than writing them as plain events).  Best results   will be obtained if an RDF document is provided with your plugins   (for example, <code>vamp-example-plugins.n3</code>) and you have this installed   in the same location as the plugins.  To override this enhanced   output and write plain events for all features, use <code>--rdf-plain</code>.
151 1 Chris Cannam
152 1 Chris Cannam
The output RDF will include an <code>available_as</code> property linking the   results to the original audio signal URI.  By default, this will   point to the URI of the file or resource containing the audio that   Sonic Annotator processed, such as the <code>file:///</code> location on disk.   To override this, for example to process a local copy of a file   while generating RDF that describes a copy of it available on a   network, you can use the <code>--rdf-signal-uri</code> option to specify an   alternative signal URI.
153 1 Chris Cannam
154 1 Chris Cannam
h3. 4. Optionally, how to summarise the features
155 1 Chris Cannam
156 1 Chris Cannam
Sonic Annotator can also calculate and write summaries of features, such as mean and median values.
157 1 Chris Cannam
158 1 Chris Cannam
To obtain a summary as well as the feature results, just use the <code>-S</code> option, naming the type of summary you want (<code>min</code>, <code>max</code>, <code>mean</code>, <code>median</code>, <code>mode</code>, <code>sum</code>, <code>variance</code>, <code>sd</code> or <code>count</code>).  You can also tell it to produce only the summary, not the individual features, with <code>--summary-only</code>.
159 1 Chris Cannam
160 1 Chris Cannam
Alternatively, you can specify a summary in a transform description. The following example tells Sonic Annotator to write both the times of note onsets estimated by the simple percussion onset detector example plugin, and the variance of the plugin's onset detection function.
161 1 Chris Cannam
(It will only process the audio file and run the plugin once.)
162 1 Chris Cannam
163 1 Chris Cannam
<pre>
164 1 Chris Cannam
  @prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;.
165 1 Chris Cannam
  @prefix vamp: &lt;http://purl.org/ontology/vamp/&gt;.
166 1 Chris Cannam
  @prefix examples: &lt;http://vamp-plugins.org/rdf/plugins/vamp-example-plugins#&gt;.
167 1 Chris Cannam
  @prefix : <#>.
168 1 Chris Cannam
169 1 Chris Cannam
  :transform1 a vamp:Transform;
170 1 Chris Cannam
     vamp:plugin examples:percussiononsets ;
171 1 Chris Cannam
     vamp:output examples:percussiononsets_output_onsets .
172 1 Chris Cannam
173 1 Chris Cannam
  :transform2 a vamp:Transform;
174 1 Chris Cannam
     vamp:plugin examples:percussiononsets ;
175 1 Chris Cannam
     vamp:output examples:percussiononsets_output_detectionfunction ;
176 1 Chris Cannam
     vamp:summary_type "variance" .
177 1 Chris Cannam
</pre>
178 1 Chris Cannam
179 1 Chris Cannam
Sonic Annotator can also summarise in segments &mdash; if you provide a comma-separated list of times as an argument to the <code>--segments</code> option, it will calculate one summary for each segment bounded by the times you provided.  For example,
180 1 Chris Cannam
181 1 Chris Cannam
<pre>
182 1 Chris Cannam
  $ sonic-annotator -d vamp:vamp-example-plugins:percussiononsets:detectionfunction \
183 1 Chris Cannam
    -S variance --sumary-only --segments 1,2,3 -w csv --csv-stdout audio.wav
184 1 Chris Cannam
  (... some log output on stderr, then ...)
185 1 Chris Cannam
  "audio.wav",0.000000000,1.000000000,variance,1723.99,"(variance, continuous-time average)"
186 1 Chris Cannam
  ,1.000000000,1.000000000,variance,1981.75,"(variance, continuous-time average)"
187 1 Chris Cannam
  ,2.000000000,1.000000000,variance,1248.79,"(variance, continuous-time average)"
188 1 Chris Cannam
  ,3.000000000,7.031020407,variance,1030.06,"(variance, continuous-time average)"
189 1 Chris Cannam
</pre>
190 1 Chris Cannam
191 1 Chris Cannam
Here the first row contains a summary covering the time period from 0 to 1 second, the second from 1 to 2 seconds, the third from 2 to 3 seconds and the fourth from 3 seconds to the end of the (short) audio file.