From: Thomas Fillon Date: Mon, 30 Sep 2013 11:17:52 +0000 (+0200) Subject: Improve Yaafe analyzer and corresponding test function. X-Git-Tag: 0.5.0~59 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5eee1b6ed0a13237f49fc9e63dece8aca616e4f8;p=timeside.git Improve Yaafe analyzer and corresponding test function. * Yaafe analyzer will raise an error when yaafe-engine does not return any features. * test_yaafe now check the number of result in the result container. --- diff --git a/tests/test_yaafe.py b/tests/test_yaafe.py index daaa0a3..71dc50b 100755 --- a/tests/test_yaafe.py +++ b/tests/test_yaafe.py @@ -26,6 +26,9 @@ class TestYaafe(TestCase): # from FeaturePlan self.analyzer = Yaafe(fp) + # Expected Results + self.result_length = 3 + def testOnGuitarWithFeaturePlanFromFile(self): "runs on guitar and load Yaafe feature plan from file" self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav") @@ -39,6 +42,9 @@ class TestYaafe(TestCase): # from FeaturePlan self.analyzer = Yaafe(fp) + # Expected Results + self.result_length = 3 + def testOnGuitarWithDataFlow(self): "runs on guitar and load Yaafe dataflow from file" self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav") @@ -52,11 +58,15 @@ class TestYaafe(TestCase): # from DataFlow self.analyzer = Yaafe(df) + # Expected Results + self.result_length = 5 + def tearDown(self): decoder = FileDecoder(self.source) decoder.output_samplerate = self.sample_rate (decoder | self.analyzer).run() results = self.analyzer.results() + self.assertEquals(self.result_length, len(results)) #print results #print results.to_yaml() #print results.to_json() diff --git a/timeside/analyzer/yaafe.py b/timeside/analyzer/yaafe.py index b9787f6..1ae8b7e 100644 --- a/timeside/analyzer/yaafe.py +++ b/timeside/analyzer/yaafe.py @@ -85,6 +85,8 @@ class Yaafe(Processor): container = AnalyzerResultContainer() # Get feature extraction results from yaafe featNames = self.yaafe_engine.getOutputs().keys() + if len(featNames) == 0: + raise KeyError('Yaafe engine did not return any feature') for featName in featNames: # Define ID fields id = 'yaafe_' + featName @@ -93,14 +95,14 @@ class Yaafe(Processor): # Get results from Yaafe engine result = AnalyzerResult() - result.metadata = AnalyzerMetadata(id = id, - name = name, - unit = unit, - samplerate = self.samplerate, - blocksize = self.blocksize, - stepsize = None) - - result.data = self.yaafe_engine.readOutput(featName) # Read Yaafe Results + result.metadata = AnalyzerMetadata(id=id, + name=name, + unit=unit, + samplerate=self.samplerate, + blocksize=self.blocksize, + stepsize=None) + # Read Yaafe Results + result.data = self.yaafe_engine.readOutput(featName) # Store results in Container if len(result.data): container.add_result(result)