#! /usr/bin/env python
-from unit_timeside import *
-from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_AUBIO
-if WITH_AUBIO:
- from timeside.analyzer.aubio.aubio_melenergy import AubioMelEnergy
+from unit_timeside import unittest, TestRunner
import os
+from timeside.decoder.file import FileDecoder
+from timeside.core import get_processor
+from timeside import _WITH_AUBIO
+
-@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available')
+@unittest.skipIf(not _WITH_AUBIO, 'Aubio library is not available')
class TestAubioMelEnergy(unittest.TestCase):
def setUp(self):
- self.analyzer = AubioMelEnergy()
+ self.analyzer = get_processor('aubio_melenergy')()
def testOnSweep(self):
"runs on sweep"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "sweep.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "sweep.wav")
def testOnGuitar(self):
"runs on guitar"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "guitar.wav")
def tearDown(self):
decoder = FileDecoder(self.source)
#! /usr/bin/env python
-from unit_timeside import *
-from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_AUBIO
-if WITH_AUBIO:
- from timeside.analyzer.aubio.aubio_mfcc import AubioMfcc
+from unit_timeside import unittest, TestRunner
import os
+from timeside.decoder.file import FileDecoder
+from timeside.core import get_processor
+from timeside import _WITH_AUBIO
-@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available')
+@unittest.skipIf(not _WITH_AUBIO, 'Aubio library is not available')
class TestAubioMfcc(unittest.TestCase):
def setUp(self):
- self.analyzer = AubioMfcc()
+ self.analyzer = get_processor('aubio_mfcc')()
def testOnSweep(self):
"runs on sweep"
#! /usr/bin/env python
-from unit_timeside import *
-from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_AUBIO
-if WITH_AUBIO:
- from timeside.analyzer.aubio.aubio_pitch import AubioPitch
+from unit_timeside import unittest, TestRunner
import os
+from timeside.decoder.file import FileDecoder
+from timeside.core import get_processor
+from timeside import _WITH_AUBIO
-@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available')
+@unittest.skipIf(not _WITH_AUBIO, 'Aubio library is not available')
class TestAubioPitch(unittest.TestCase):
def setUp(self):
- self.analyzer = AubioPitch()
+ self.analyzer = get_processor('aubio_pitch')()
def testOnSweep(self):
"runs on sweep"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "sweep.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "sweep.wav")
def testOnGuitar(self):
"runs on guitar"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "guitar.wav")
def tearDown(self):
decoder = FileDecoder(self.source)
#! /usr/bin/env python
-from unit_timeside import *
-from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_AUBIO
-if WITH_AUBIO:
- from timeside.analyzer.aubio.aubio_specdesc import AubioSpecdesc
+from unit_timeside import unittest, TestRunner
import os
+from timeside.decoder.file import FileDecoder
+from timeside.core import get_processor
+from timeside import _WITH_AUBIO
-@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available')
+@unittest.skipIf(not _WITH_AUBIO, 'Aubio library is not available')
class TestAubioSpecdesc(unittest.TestCase):
def setUp(self):
- self.analyzer = AubioSpecdesc()
+ self.analyzer = get_processor('aubio_specdesc')()
def testOnSweep(self):
"runs on sweep"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "sweep.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "sweep.wav")
def testOnGuitar(self):
"runs on guitar"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "guitar.wav")
def tearDown(self):
decoder = FileDecoder(self.source)
#! /usr/bin/env python
-from unit_timeside import *
-from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_AUBIO
-if WITH_AUBIO:
- from timeside.analyzer.aubio.aubio_temporal import AubioTemporal
+from unit_timeside import unittest, TestRunner
import os
+from timeside.decoder.file import FileDecoder
+from timeside.core import get_processor
+from timeside import _WITH_AUBIO
-@unittest.skipIf(not WITH_AUBIO, 'Aubio library is not available')
+@unittest.skipIf(not _WITH_AUBIO, 'Aubio library is not available')
class TestAubioTemporal(unittest.TestCase):
def setUp(self):
- self.analyzer = AubioTemporal()
+ self.analyzer = get_processor('aubio_temporal')()
def testOnSweep(self):
"runs on sweep"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "sweep.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "sweep.wav")
def testOnGuitar(self):
"runs on guitar"
- self.source = os.path.join (os.path.dirname(__file__), "samples", "guitar.wav")
+ self.source = os.path.join(os.path.dirname(__file__),
+ "samples", "guitar.wav")
def tearDown(self):
decoder = FileDecoder(self.source)
from unit_timeside import TestRunner
import doctest
import timeside
-import pkgutil
+from timeside.tools.package import discover_modules
def load_tests(loader, tests, ignore):
finder = doctest.DocTestFinder(exclude_empty=False)
# Create tests for doctest in timeside modules and sub-modules
- modules_list = [modname for _, modname, _ in pkgutil.walk_packages(
- path=timeside.__path__,
- prefix=timeside.__name__ + '.',
- onerror=lambda x: None)]
+ modules_list = discover_modules(timeside.__name__)
for module in modules_list:
_tmp = __import__(module, fromlist=['DOCTEST_ALIAS'])
DOCTEST_ALIAS = _tmp.DOCTEST_ALIAS
except AttributeError:
DOCTEST_ALIAS = {}
+
tests.addTests(doctest.DocTestSuite(module, extraglobs=DOCTEST_ALIAS,
test_finder=finder))
from unit_timeside import *
from timeside.decoder.file import FileDecoder
-from timeside.analyzer import WITH_YAAFE
-if WITH_YAAFE:
+from timeside import _WITH_YAAFE
+if _WITH_YAAFE:
from timeside.analyzer.yaafe import Yaafe
from yaafelib import DataFlow, FeaturePlan
import os
-@unittest.skipIf(not WITH_YAAFE, 'Yaafe library is not available')
+@unittest.skipIf(not _WITH_YAAFE, 'Yaafe library is not available')
class TestYaafe(unittest.TestCase):
def setUp(self):
from . import api
from . import core
-from . import decoder
-from . import analyzer
-from . import grapher
-from . import encoder
__version__ = '0.5.5'
-__all__ = ['api', 'core', 'decoder', 'analyzer', 'grapher', 'encoder']
+# Check Availability of external Audio feature extraction librairies
+from .tools import package as ts_package
+_WITH_AUBIO = ts_package.check_aubio()
+_WITH_YAAFE = ts_package.check_yaafe()
+_WITH_VAMP = ts_package.check_vamp()
-def _discover_modules():
- import sys
- import pkgutil
- import importlib
+_packages_with_processors = ['decoder', 'analyzer', 'encoder', 'grapher']
- #pkg_path = os.path.abspath()
+__all__ = ['api', 'core']
+__all__.extend(_packages_with_processors)
- #__import__(pkg)
+for _sub_pkg in _packages_with_processors:
+ ts_package.discover_modules(_sub_pkg, __name__)
- proc_modules = ['decoder', 'analyzer', 'encoder', 'grapher']
-
- for module in proc_modules:
- pkg = '.'.join([__name__, module])
- importlib.import_module(pkg)
- package = sys.modules[pkg]
- prefix = pkg + "."
-
- for importer, modname, ispkg in pkgutil.walk_packages(package.__path__,
- prefix):
- try:
- importlib.import_module(modname)
- #__import__(modname)
- except ImportError as e:
- if e.message.count('yaafelib'):
- print 'No Yaafe'
- elif e.message.count('aubio'):
- print 'No Aubio'
- else:
- raise e
-
-_discover_modules()
+# Clean-up
+del ts_package
+del _packages_with_processors
+del _sub_pkg
+del absolute_import
-# -*- coding: utf-8 -*-
-from __future__ import absolute_import
-
-# ----- Load external libraries ------
-# Aubio
-try:
- WITH_AUBIO = True
- import aubio
-except ImportError:
- WITH_AUBIO = False
-else:
- del aubio
-
-# Yaafe
-try:
- WITH_YAAFE = True
- import yaafelib
-except ImportError:
- WITH_YAAFE = False
-else:
- del yaafelib
-
-# Vamp Plugins
-try:
- from . vamp_plugin import VampSimpleHost
- VampSimpleHost.SimpleHostProcess(['-v'])
- WITH_VAMP = True
-except OSError:
- WITH_VAMP = False
from timeside.analyzer.core import Analyzer
from timeside.api import IAnalyzer
import timeside
-#from timeside.analyzer import WITH_YAAFE
-WITH_YAAFE = True
-if WITH_YAAFE:
- from yaafe import Yaafe
- import yaafelib
+
+import yaafelib
import numpy as N
import pickle
import os.path
import numpy as np
+def simple_host_process(argslist):
+ """Call vamp-simple-host"""
+
+ vamp_host = 'vamp-simple-hostqq'
+ command = [vamp_host]
+ command.extend(argslist)
+ # try ?
+ stdout = subprocess.check_output(
+ command, stderr=subprocess.STDOUT).splitlines()
+
+ return stdout
+
+
+# Raise an exception if Vamp Host is missing
+from ..exceptions import VampImportError
+try:
+ simple_host_process(['-v'])
+ WITH_VAMP = True
+except OSError:
+ WITH_VAMP = False
+ raise VampImportError
+
+
class VampSimpleHost(Analyzer):
"""Vamp plugins library interface analyzer"""
args = [plugin, wavfile]
- stdout = VampSimpleHost.SimpleHostProcess(args) # run vamp-simple-host
+ stdout = simple_host_process(args) # run vamp-simple-host
stderr = stdout[0:8] # stderr containing file and process information
res = stdout[8:] # stdout containg the feature data
@staticmethod
def get_plugins_list():
arg = ['--list-outputs']
- stdout = VampSimpleHost.SimpleHostProcess(arg)
+ stdout = simple_host_process(arg)
return [line.split(':')[1:] for line in stdout]
-
- @staticmethod
- def SimpleHostProcess(argslist):
- """Call vamp-simple-host"""
-
- vamp_host = 'vamp-simple-host'
- command = [vamp_host]
- command.extend(argslist)
- # try ?
- stdout = subprocess.check_output(
- command, stderr=subprocess.STDOUT).splitlines()
-
- return stdout
from timeside.core import implements, interfacedoc
from timeside.analyzer.core import Analyzer
from timeside.api import IAnalyzer
-#from timeside.analyzer import WITH_YAAFE
-WITH_YAAFE = True
-if WITH_YAAFE:
- import yaafelib
+
+import yaafelib
import numpy
from timeside.analyzer.preprocessors import downmix_to_mono
from .component import Component, MetaComponent, abstract
from .component import implements, implementations, interfacedoc
from .api import IProcessor
-from .exceptions import Error, ApiError
+from .exceptions import Error, PIDError, ApiError
import re
import numpy
def get_processor(processor_id):
"""Return a processor by its id"""
if not processor_id in _processors:
- raise Error("No processor registered with id: '%s'"
+ raise PIDError("No processor registered with id: '%s'"
% processor_id)
return _processors[processor_id]
return "%s ; command: %s; error: %s" % (self.message,
self.command,
error)
+
+
+class PIDError(KeyError):
+ "Exception for reporting missing Processor ID in registered processors"
+
+
+class VampImportError(ImportError):
+ "Can't import module depending on Vamp because vamp host is missing"
# (at your option) any later version.
# TimeSide is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# but _WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
-from timeside.core import implements, interfacedoc, abstract, get_processor
-from timeside.api import IGrapher
-from core import Grapher
-from .. import analyzer
+from ..core import implements, interfacedoc, abstract, get_processor
+from ..api import IGrapher
+from .core import Grapher
+from ..exceptions import PIDError
class DisplayAnalyzer(Grapher):
# From here define new Grapher based on Analyzers
-if analyzer.WITH_AUBIO:
+try:
aubiopitch = get_processor('aubio_pitch')
DisplayAubioPitch = DisplayAnalyzer.create(analyzer=aubiopitch,
result_id='aubio_pitch.pitch',
grapher_id='grapher_aubio_pitch',
grapher_name='Aubio Pitch')
-
+except PIDError:
+ pass
odf = get_processor('odf')
DisplayOnsetDetectionFunction = DisplayAnalyzer.create(analyzer=odf,
result_id='waveform_analyzer',
grapher_id='grapher_waveform',
grapher_name='Waveform from Analyzer')
+
irit4hz = get_processor('irit_speech_4hz')
Display4hzSpeechSegmentation = DisplayAnalyzer.create(analyzer=irit4hz,
result_id='irit_speech_4hz.segments',
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013-2014 Thomas Fillon <thomas.fillon@parisson.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Thomas Fillon <thomas.fillon@parisson.com>
+
+from ..exceptions import VampImportError
+
+from importlib import import_module
+import warnings
+
+
+def discover_modules(subpackage, package=None):
+ import pkgutil
+
+ if package:
+ _pkg = import_module('.' + subpackage, package)
+ else:
+ _pkg = import_module(subpackage)
+
+ pkg_path = _pkg.__path__
+ pkg_prefix = _pkg.__name__ + '.'
+
+ _list = [import_module_with_exceptions(modname)
+ for importer, modname, ispkg
+ in pkgutil.walk_packages(pkg_path, pkg_prefix)]
+
+ modules_list = [mod for mod in _list if mod is not None]
+ return modules_list
+
+
+def import_module_with_exceptions(name, package=None):
+ """Wrapper around importlib.import_module to import TimeSide subpackage
+ and ignoring ImportError if Aubio, Yaafe and Vamp Host are not available"""
+
+ from timeside import _WITH_AUBIO, _WITH_YAAFE, _WITH_VAMP
+
+ if name.count('.server.'):
+ # TODO:
+ # Temporary skip all timeside.server submodules before check dependencies
+ return
+ try:
+ import_module(name, package)
+ except VampImportError:
+ # No Vamp Host
+ if _WITH_VAMP:
+ raise VampImportError
+ else:
+ # Ignore Vamp ImportError
+ return
+ except ImportError as e:
+ if str(e).count('yaafelib') and not _WITH_YAAFE:
+ # Ignore Yaafe ImportError
+ return
+ elif str(e).count('aubio') and not _WITH_AUBIO:
+ # Ignore Aubio ImportError
+ return
+ elif str(e).count('DJANGO_SETTINGS_MODULE'):
+ # Ignore module requiring DJANGO_SETTINGS_MODULE in environnement
+ return
+ else:
+ raise e
+ return name
+
+
+# Check Availability of external Audio feature extraction librairies
+def check_aubio():
+ "Check Aubio availability"
+ try:
+ import aubio
+ except ImportError:
+ warnings.warn('Aubio librairy is not available', ImportWarning,
+ stacklevel=2)
+ _WITH_AUBIO = False
+ else:
+ _WITH_AUBIO = True
+ del aubio
+
+ return _WITH_AUBIO
+
+
+def check_yaafe():
+ "Check Aubio availability"
+ try:
+ import yaafelib
+ except ImportError:
+ warnings.warn('Yaafe librairy is not available', ImportWarning,
+ stacklevel=2)
+ _WITH_YAAFE = False
+ else:
+ _WITH_YAAFE = True
+ del yaafelib
+ return _WITH_YAAFE
+
+
+def check_vamp():
+ "Check Vamp host availability"
+
+ try:
+ from ..analyzer import vamp_plugin
+ except VampImportError:
+ warnings.warn('Vamp host is not available', ImportWarning,
+ stacklevel=2)
+ _WITH_VAMP = False
+ else:
+ _WITH_VAMP = True
+ del vamp_plugin
+
+ return _WITH_VAMP