From: Thomas Fillon Date: Thu, 2 Oct 2014 19:02:02 +0000 (+0200) Subject: chore(analyzer): add traits support for all analyzer X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e28f98354ce7abab63615a1ea417053b2733e688;p=timeside-diadems.git chore(analyzer): add traits support for all analyzer Also add a test to chack if analyzer __init__ arguments are also defined as traits parameters. --- diff --git a/timeside/analyzer/irit_noise_startSilences.py b/timeside/analyzer/irit_noise_startSilences.py index 7b77400..60f55cb 100644 --- a/timeside/analyzer/irit_noise_startSilences.py +++ b/timeside/analyzer/irit_noise_startSilences.py @@ -42,11 +42,9 @@ class IRITStartSeg(Analyzer): Properties: ''' @interfacedoc - def __init__(self, save_lab=False): + def __init__(self): super(IRITStartSeg, self).__init__() - self._save_lab = save_lab - self._buffer = BufferTable() # self.energy = [] @@ -54,6 +52,7 @@ class IRITStartSeg(Analyzer): self.max_energy = 0.002*2 self.min_overlap = 20 self.threshold = 0.12 + @interfacedoc def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): @@ -164,19 +163,6 @@ class IRITStartSeg(Analyzer): label = {0: 'Start', 1: 'Session'} - if self._save_lab: - with open('out.lab', 'w') as f: - for s in selected_segs: - f.write( - '%.2f\t%.2f\t%s\n' % - (s[0] * step, s[1] * step, label[s[2]])) - - with open('cand.lab', 'w') as f: - for s in candidates: - f.write('%.2f\t%.2f\t%f\n' % (s[0] * step, - s[1] * step, - s[2])) - segs = self.new_result(data_mode='label', time_mode='segment') segs.id_metadata.id += '.' + 'segments' segs.id_metadata.name += ' ' + 'Segments' diff --git a/timeside/analyzer/irit_speech_4hz.py b/timeside/analyzer/irit_speech_4hz.py index a64c4ff..385f10e 100644 --- a/timeside/analyzer/irit_speech_4hz.py +++ b/timeside/analyzer/irit_speech_4hz.py @@ -28,6 +28,8 @@ from numpy import array, hamming, dot, mean, float, mod from numpy.fft import rfft from scipy.signal import firwin, lfilter +from ..tools.parameters import Float, HasTraits + class IRITSpeech4Hz(Analyzer): @@ -48,6 +50,10 @@ class IRITSpeech4Hz(Analyzer): implements(IAnalyzer) + # Define Parameters + class _Param(HasTraits): + medfilt_duration = Float() + @interfacedoc def __init__(self, medfilt_duration=5): super(IRITSpeech4Hz, self).__init__() diff --git a/timeside/analyzer/limsi_sad.py b/timeside/analyzer/limsi_sad.py index ba18b83..2d0af7b 100644 --- a/timeside/analyzer/limsi_sad.py +++ b/timeside/analyzer/limsi_sad.py @@ -24,6 +24,8 @@ from timeside.analyzer.core import Analyzer from timeside.api import IAnalyzer import timeside +from ..tools.parameters import Enum, HasTraits + import yaafelib import numpy as np import pickle @@ -62,6 +64,10 @@ class LimsiSad(Analyzer): """ implements(IAnalyzer) + # Define Parameters + class _Param(HasTraits): + sad_model = Enum('etape', 'maya') + def __init__(self, sad_model='etape'): """ Parameters: @@ -74,16 +80,13 @@ class LimsiSad(Analyzer): super(LimsiSad, self).__init__() # feature extraction defition - spec = yaafelib.FeaturePlan(sample_rate=16000) - spec.addFeature( - 'mfcc: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256') - spec.addFeature( - 'mfccd1: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=1') - spec.addFeature( - 'mfccd2: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=2') - spec.addFeature('zcr: ZCR blockSize=1024 stepSize=256') - parent_analyzer = get_processor('yaafe')(spec) - self.parents['yaafe'] = parent_analyzer + feature_plan = ['mfcc: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256', + 'mfccd1: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=1', + 'mfccd2: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=2', + 'zcr: ZCR blockSize=1024 stepSize=256'] + yaafe_analyzer = get_processor('yaafe') + self.parents['yaafe'] = yaafe_analyzer(feature_plan=feature_plan, + input_samplerate=16000) # informative parameters # these are not really taken into account by the system @@ -95,6 +98,7 @@ class LimsiSad(Analyzer): if sad_model not in ['etape', 'maya']: raise ValueError( "argument sad_model %s not supported. Supported values are 'etape' or 'maya'" % sad_model) + self.sad_model = sad_model picfname = os.path.join( timeside.__path__[0], 'analyzer', 'trained_models', 'limsi_sad_%s.pkl' % sad_model) self.gmms = pickle.load(open(picfname, 'rb'))