comparison vamp/process.py @ 112:9343eee50605

Update to Python 3. Currently crashes during tests (and also, two tests are now failing, even with Py2).
author Chris Cannam
date Wed, 17 Jun 2015 12:35:41 +0100
parents 72be91c3cb3d
children 2370b942cd32
comparison
equal deleted inserted replaced
111:4f590fc46ace 112:9343eee50605
1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.''' 1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.'''
2 2
3 import vampyhost 3 import vampyhost
4 import frames 4 import vamp.frames
5 import load 5 import vamp.load
6 6
7 def process_with_initialised_plugin(ff, sample_rate, step_size, plugin, outputs): 7 def process_with_initialised_plugin(ff, sample_rate, step_size, plugin, outputs):
8 8
9 out_indices = dict([(id, plugin.get_output(id)["output_index"]) 9 out_indices = dict([(id, plugin.get_output(id)["output_index"])
10 for id in outputs]) 10 for id in outputs])
28 if ix in results: 28 if ix in results:
29 for r in results[ix]: 29 for r in results[ix]:
30 yield { o: r } 30 yield { o: r }
31 31
32 32
33 def process(data, sample_rate, key, output = "", parameters = {}): 33 def process_audio(data, sample_rate, key, output = "", parameters = {}):
34 """Process audio data with a Vamp plugin, and make the results from a 34 """Process audio data with a Vamp plugin, and make the results from a
35 single plugin output available as a generator. 35 single plugin output available as a generator.
36 36
37 The provided data should be a 1- or 2-dimensional list or NumPy 37 The provided data should be a 1- or 2-dimensional list or NumPy
38 array of floats. If it is 2-dimensional, the first dimension is 38 array of floats. If it is 2-dimensional, the first dimension is
55 55
56 If you would prefer to obtain all features in a single output 56 If you would prefer to obtain all features in a single output
57 structure, consider using vamp.collect() instead. 57 structure, consider using vamp.collect() instead.
58 """ 58 """
59 59
60 plugin, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters) 60 plugin, step_size, block_size = vamp.load.load_and_configure(data, sample_rate, key, parameters)
61 61
62 if output == "": 62 if output == "":
63 output = plugin.get_output(0)["identifier"] 63 output = plugin.get_output(0)["identifier"]
64 64
65 ff = frames.frames_from_array(data, step_size, block_size) 65 ff = vamp.frames.frames_from_array(data, step_size, block_size)
66 66
67 for r in process_with_initialised_plugin(ff, sample_rate, step_size, plugin, [output]): 67 for r in process_with_initialised_plugin(ff, sample_rate, step_size, plugin, [output]):
68 yield r[output] 68 yield r[output]
69 69
70 plugin.unload() 70 plugin.unload()
162 represented as a dictionary containing, optionally, timestamp and 162 represented as a dictionary containing, optionally, timestamp and
163 duration (RealTime objects), label (string), and a 1-dimensional 163 duration (RealTime objects), label (string), and a 1-dimensional
164 array of float values. 164 array of float values.
165 """ 165 """
166 166
167 plugin, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters) 167 plugin, step_size, block_size = vamp.load.load_and_configure(data, sample_rate, key, parameters)
168 168
169 ff = frames.frames_from_array(data, step_size, block_size) 169 ff = vamp.frames.frames_from_array(data, step_size, block_size)
170 170
171 for r in process_with_initialised_plugin(ff, sample_rate, step_size, plugin, outputs): 171 for r in process_with_initialised_plugin(ff, sample_rate, step_size, plugin, outputs):
172 yield r 172 yield r
173 173
174 plugin.unload() 174 plugin.unload()