From: David Doukhan Date: Fri, 11 Jul 2014 14:49:35 +0000 (+0200) Subject: export analyzer result to sonic visualizer X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=bd5dd68b736eca85a14fbdfb33029a42b7c29b47;p=timeside.git export analyzer result to sonic visualizer --- diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 9da3049..2aed37f 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -21,6 +21,7 @@ # Guillaume Pellerin # Paul Brossier # Thomas Fillon +# David Doukhan from __future__ import division from timeside.core import Processor @@ -29,6 +30,7 @@ import numpy from collections import OrderedDict import h5py import h5tools +from py_sonicvisualiser import SVEnv import os if os.environ.has_key('DISPLAY'): @@ -958,6 +960,28 @@ class AnalyzerResultContainer(dict): return results + def to_sonicvisualiser(self, output_file): + assert(len(self) > 0) + uri = self[self.keys()[0]].audio_metadata['uri'] + assert(len(uri) > 7 and uri[:7] == 'file://') + sve = SVEnv.init_from_wave_file(uri[7:]) + for k in self: + res = self[k] + time = res.time + data = res.data + if res.data_mode == 'value': + labels = None + elif res.data_mode == 'label': + labdic = res.label_metadata.label + labels = [labdic[k] for k in data] + else: + raise NotImplementedError() + if res.time_mode != 'segment': + sve.add_continuous_annotations(time, res.data, presentationName=k) + else: + sve.add_interval_annotations(time, res.duration, labels, values=res.data, presentationName=k) + + sve.save(output_file) class Analyzer(Processor):