1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Module Yaafe Analyzer
23 Created on Thu Jun 13 16:05:02 2013
24
25 @author: Thomas Fillon
26 """
27 from timeside.core import implements, interfacedoc
28 from timeside.analyzer.core import Analyzer
29 from timeside.api import IAnalyzer
30 from yaafelib import *
31 import numpy
32
33
34 -class Yaafe(Analyzer):
35 implements(IAnalyzer)
36
37 - def __init__(self, yaafeSpecification=None):
38 super(Yaafe,self).__init__()
39
40
41 if yaafeSpecification is None:
42 yaafeSpecification = FeaturePlan(sample_rate=32000)
43
44 yaafeSpecification.addFeature('mfcc: MFCC blockSize=512 stepSize=256')
45
46 if isinstance(yaafeSpecification, DataFlow):
47 self.dataFlow = yaafeSpecification
48 elif isinstance(yaafeSpecification, FeaturePlan):
49 self.featurePlan = yaafeSpecification
50 self.dataFlow = self.featurePlan.getDataFlow()
51 else:
52 raise TypeError("'%s' Type must be either '%s' or '%s'" %
53 (str(yaafeSpecification),
54 str(DataFlow),
55 str(FeaturePlan)))
56 self.yaafe_engine = None
57
58
59 @interfacedoc
60 - def setup(self, channels=None, samplerate=None,
61 blocksize=None, totalframes=None):
69
70 @staticmethod
71 @interfacedoc
74
75 @staticmethod
76 @interfacedoc
78 return "Yaafe Descriptor"
79
80 @staticmethod
81 @interfacedoc
84
85 - def process(self, frames, eod=False):
86
87
88
89 yaafe_frames = frames.sum(
90 axis=-1, dtype=numpy.float64) / frames.shape[-1]
91
92 yaafe_frames.shape = (1, yaafe_frames.shape[0])
93
94 self.yaafe_engine.writeInput('audio', yaafe_frames)
95
96 self.yaafe_engine.process()
97 if eod:
98
99 self.yaafe_engine.flush()
100
101 return frames, eod
102
103 - def post_process(self):
104
105 featNames = self.yaafe_engine.getOutputs().keys()
106 if len(featNames) == 0:
107 raise KeyError('Yaafe engine did not return any feature')
108 for featName in featNames:
109
110 result = self.new_result(data_mode='value', time_mode='framewise')
111 result.id_metadata.id += '.' + featName
112 result.id_metadata.name += ' ' + featName
113
114 result.data_object.value = self.yaafe_engine.readOutput(featName)
115
116 if len(result.data_object.value):
117 self.process_pipe.results.add(result)
118