From 5e644c4bf826adb4cc61a5a211a15aad6f100655 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Mon, 14 Apr 2014 23:02:41 +0200 Subject: [PATCH] Enable TimeSide to work without external libraries such as Yafe, Aubio, Vamp Add automatic detection of Yaafe, Aubio and Vamp and add a conditional import of related analyzers in timeside/anaylers/__init__.py --- tests/test_aubio_melenergy.py | 6 ++++- tests/test_aubio_mfcc.py | 6 ++++- tests/test_aubio_pitch.py | 6 ++++- tests/test_aubio_specdesc.py | 6 ++++- tests/test_aubio_temporal.py | 6 ++++- tests/test_yaafe.py | 8 +++++-- timeside/analyzer/__init__.py | 40 +++++++++++++++++++++++++++------- timeside/analyzer/limsi_sad.py | 6 +++-- timeside/analyzer/yaafe.py | 4 +++- 9 files changed, 70 insertions(+), 18 deletions(-) diff --git a/tests/test_aubio_melenergy.py b/tests/test_aubio_melenergy.py index 274e032..16506ac 100755 --- a/tests/test_aubio_melenergy.py +++ b/tests/test_aubio_melenergy.py @@ -2,8 +2,12 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer.aubio_melenergy import AubioMelEnergy +from timeside.analyzer import WITH_AUBIO +if WITH_AUBIO: + from timeside.analyzer.aubio_melenergy import AubioMelEnergy + +@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available') class TestAubioMelEnergy(unittest.TestCase): def setUp(self): diff --git a/tests/test_aubio_mfcc.py b/tests/test_aubio_mfcc.py index 8bcffef..e774aca 100755 --- a/tests/test_aubio_mfcc.py +++ b/tests/test_aubio_mfcc.py @@ -2,8 +2,12 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer.aubio_mfcc import AubioMfcc +from timeside.analyzer import WITH_AUBIO +if WITH_AUBIO: + from timeside.analyzer.aubio_mfcc import AubioMfcc + +@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available') class TestAubioMfcc(unittest.TestCase): def setUp(self): diff --git a/tests/test_aubio_pitch.py b/tests/test_aubio_pitch.py index 557e797..9de6b81 100755 --- a/tests/test_aubio_pitch.py +++ b/tests/test_aubio_pitch.py @@ -2,8 +2,12 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer.aubio_pitch import AubioPitch +from timeside.analyzer import WITH_AUBIO +if WITH_AUBIO: + from timeside.analyzer.aubio_pitch import AubioPitch + +@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available') class TestAubioPitch(unittest.TestCase): def setUp(self): diff --git a/tests/test_aubio_specdesc.py b/tests/test_aubio_specdesc.py index f4341ec..51dfaff 100755 --- a/tests/test_aubio_specdesc.py +++ b/tests/test_aubio_specdesc.py @@ -2,8 +2,12 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer.aubio_specdesc import AubioSpecdesc +from timeside.analyzer import WITH_AUBIO +if WITH_AUBIO: + from timeside.analyzer.aubio_specdesc import AubioSpecdesc + +@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available') class TestAubioSpecdesc(unittest.TestCase): def setUp(self): diff --git a/tests/test_aubio_temporal.py b/tests/test_aubio_temporal.py index 9ffba1b..9f6d5ac 100755 --- a/tests/test_aubio_temporal.py +++ b/tests/test_aubio_temporal.py @@ -2,8 +2,12 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer.aubio_temporal import AubioTemporal +from timeside.analyzer import WITH_AUBIO +if WITH_AUBIO: + from timeside.analyzer.aubio_temporal import AubioTemporal + +@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available') class TestAubioTemporal(unittest.TestCase): def setUp(self): diff --git a/tests/test_yaafe.py b/tests/test_yaafe.py index d0c7142..714893f 100755 --- a/tests/test_yaafe.py +++ b/tests/test_yaafe.py @@ -2,9 +2,13 @@ from unit_timeside import * from timeside.decoder import * -from timeside.analyzer import Yaafe -from yaafelib import DataFlow,FeaturePlan +from timeside.analyzer import WITH_YAAFE +if WITH_YAAFE: + from timeside.analyzer import Yaafe + from yaafelib import DataFlow, FeaturePlan + +@unittest.skipIf(not WITH_YAAFE, 'Yaafe library is not available') class TestYaafe(unittest.TestCase): def setUp(self): diff --git a/timeside/analyzer/__init__.py b/timeside/analyzer/__init__.py index 27aa32d..3f5eb52 100644 --- a/timeside/analyzer/__init__.py +++ b/timeside/analyzer/__init__.py @@ -1,17 +1,41 @@ # -*- coding: utf-8 -*- +# ----- Load external libraries ------ +# Aubio +try: + WITH_AUBIO = True + from aubio_temporal import AubioTemporal + from aubio_pitch import AubioPitch + from aubio_mfcc import * + from aubio_melenergy import * + from aubio_specdesc import * +except ImportError: + WITH_AUBIO = False + +# Yaafe +try: + WITH_YAAFE = True + from yaafe import * + +except ImportError: + WITH_YAAFE = False + +# Vamp Plugins +try: + from vamp_plugin import VampSimpleHost + VampSimpleHost.SimpleHostProcess(['-v']) + WITH_VAMP = True +except OSError: + WITH_VAMP = False + + +# ----- Load timeside analyzers ------ from level import Level from dc import MeanDCShift -from aubio_temporal import AubioTemporal -from aubio_pitch import AubioPitch -from aubio_mfcc import * -from aubio_melenergy import * -from aubio_specdesc import * -from yaafe import * from spectrogram import Spectrogram from waveform import Waveform -from vamp_plugin import VampSimpleHost from irit_speech_entropy import IRITSpeechEntropy from irit_speech_4hz import IRITSpeech4Hz from odf import OnsetDetectionFunction -from limsi_sad import LimsiSad +if WITH_YAAFE: + from limsi_sad import LimsiSad diff --git a/timeside/analyzer/limsi_sad.py b/timeside/analyzer/limsi_sad.py index 5586aad..5a5afa0 100644 --- a/timeside/analyzer/limsi_sad.py +++ b/timeside/analyzer/limsi_sad.py @@ -23,8 +23,10 @@ from timeside.core import implements, interfacedoc from timeside.analyzer.core import Analyzer from timeside.api import IAnalyzer import timeside -from yaafe import Yaafe -import yaafelib +from timeside.analyzer import WITH_YAAFE +if WITH_YAAFE: + from yaafe import Yaafe + import yaafelib import numpy as N import pickle import os.path diff --git a/timeside/analyzer/yaafe.py b/timeside/analyzer/yaafe.py index ab069bb..1a3fa2c 100644 --- a/timeside/analyzer/yaafe.py +++ b/timeside/analyzer/yaafe.py @@ -27,7 +27,9 @@ Created on Thu Jun 13 16:05:02 2013 from timeside.core import implements, interfacedoc from timeside.analyzer.core import Analyzer from timeside.api import IAnalyzer -from yaafelib import * +from timeside.analyzer import WITH_YAAFE +if WITH_YAAFE: + from yaafelib import * import numpy from timeside.analyzer.preprocessors import downmix_to_mono -- 2.39.5