From 0cdc1e8b7d913cb1700417d27e46ffeb8dee7ea1 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Tue, 22 Apr 2014 15:23:41 +0200 Subject: [PATCH] Fix PEP8 on timeside.analyzer with autopep8 --- timeside/analyzer/aubio_melenergy.py | 1 + timeside/analyzer/aubio_mfcc.py | 1 + timeside/analyzer/aubio_pitch.py | 13 ++- timeside/analyzer/aubio_specdesc.py | 1 + timeside/analyzer/aubio_temporal.py | 5 +- timeside/analyzer/core.py | 11 +- timeside/analyzer/dc.py | 1 + timeside/analyzer/irit_speech_4hz.py | 3 +- timeside/analyzer/irit_speech_entropy.py | 3 +- timeside/analyzer/level.py | 7 +- timeside/analyzer/limsi_sad.py | 39 ++++--- timeside/analyzer/odf.py | 3 +- timeside/analyzer/preprocessors.py | 5 +- timeside/analyzer/spectrogram.py | 3 +- timeside/analyzer/utils.py | 129 ++++++++++++----------- timeside/analyzer/vamp_plugin.py | 17 +-- timeside/analyzer/waveform.py | 4 +- timeside/analyzer/yaafe.py | 9 +- 18 files changed, 146 insertions(+), 109 deletions(-) diff --git a/timeside/analyzer/aubio_melenergy.py b/timeside/analyzer/aubio_melenergy.py index 9941fca..8bb8616 100644 --- a/timeside/analyzer/aubio_melenergy.py +++ b/timeside/analyzer/aubio_melenergy.py @@ -29,6 +29,7 @@ from aubio import filterbank, pvoc class AubioMelEnergy(Analyzer): + """Aubio Mel Energy analyzer""" implements(IAnalyzer) diff --git a/timeside/analyzer/aubio_mfcc.py b/timeside/analyzer/aubio_mfcc.py index 6579c3a..36bc208 100644 --- a/timeside/analyzer/aubio_mfcc.py +++ b/timeside/analyzer/aubio_mfcc.py @@ -29,6 +29,7 @@ from aubio import mfcc, pvoc class AubioMfcc(Analyzer): + """Aubio MFCC analyzer""" implements(IAnalyzer) diff --git a/timeside/analyzer/aubio_pitch.py b/timeside/analyzer/aubio_pitch.py index 6769445..4e1c764 100644 --- a/timeside/analyzer/aubio_pitch.py +++ b/timeside/analyzer/aubio_pitch.py @@ -26,7 +26,9 @@ from preprocessors import downmix_to_mono, frames_adapter from aubio import pitch import numpy as np + class AubioPitch(Analyzer): + """Aubio Pitch estimation analyzer""" implements(IAnalyzer) # TODO check if needed with inheritance @@ -42,8 +44,9 @@ class AubioPitch(Analyzer): samplerate, blocksize, totalframes) - self.aubio_pitch = pitch("default", self.input_blocksize, self.input_stepsize, - samplerate) + self.aubio_pitch = pitch( + "default", self.input_blocksize, self.input_stepsize, + samplerate) self.aubio_pitch.set_unit("freq") self.block_read = 0 self.pitches = [] @@ -72,7 +75,8 @@ class AubioPitch(Analyzer): def process(self, frames, eod=False): #time = self.block_read * self.input_stepsize * 1. / self.samplerate() self.pitches += [self.aubio_pitch(frames)[0]] - self.pitch_confidences += [np.nan_to_num(self.aubio_pitch.get_confidence())] + self.pitch_confidences += [ + np.nan_to_num(self.aubio_pitch.get_confidence())] self.block_read += 1 return frames, eod @@ -88,7 +92,8 @@ class AubioPitch(Analyzer): pitch.data_object.value = self.pitches self.process_pipe.results.add(pitch) - pitch_confidence = self.new_result(data_mode='value', time_mode='framewise') + pitch_confidence = self.new_result( + data_mode='value', time_mode='framewise') pitch_confidence.id_metadata.id += '.' + "pitch_confidence" pitch_confidence.id_metadata.name += ' ' + "pitch confidence" pitch_confidence.id_metadata.unit = None diff --git a/timeside/analyzer/aubio_specdesc.py b/timeside/analyzer/aubio_specdesc.py index 94fbbe7..cc19fb6 100644 --- a/timeside/analyzer/aubio_specdesc.py +++ b/timeside/analyzer/aubio_specdesc.py @@ -28,6 +28,7 @@ from aubio import specdesc, pvoc class AubioSpecdesc(Analyzer): + """Aubio Spectral Descriptors collection analyzer""" implements(IAnalyzer) diff --git a/timeside/analyzer/aubio_temporal.py b/timeside/analyzer/aubio_temporal.py index 4ada859..f4be03f 100644 --- a/timeside/analyzer/aubio_temporal.py +++ b/timeside/analyzer/aubio_temporal.py @@ -29,6 +29,7 @@ import numpy class AubioTemporal(Analyzer): + """Aubio Temporal analyzer""" implements(IAnalyzer) @@ -72,7 +73,6 @@ class AubioTemporal(Analyzer): def __str__(self): return "%s %s" % (str(self.value), self.unit()) - @downmix_to_mono @frames_adapter def process(self, frames, eod=False): @@ -134,7 +134,8 @@ class AubioTemporal(Analyzer): #--------------------------------- # Beat confidences: Event (time, value) #--------------------------------- - beat_confidences = self.new_result(data_mode='value', time_mode='event') + beat_confidences = self.new_result( + data_mode='value', time_mode='event') beat_confidences.id_metadata.id += '.' + "beat_confidence" beat_confidences.id_metadata.name += " " + "Beat confidences" beat_confidences.id_metadata.unit = None diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 32e33dc..384be37 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -25,7 +25,7 @@ from __future__ import division from timeside.core import Processor -import timeside #import __version__ +import timeside # import __version__ import numpy from collections import OrderedDict import h5py @@ -440,7 +440,8 @@ class DataObject(MetadataObject): maxshape = None else: maxshape = (None,) - h5group.create_dataset(key, data=self.__getattribute__(key), maxshape = maxshape) + h5group.create_dataset( + key, data=self.__getattribute__(key), maxshape=maxshape) def from_hdf5(self, h5group): for key, dataset in h5group.items(): @@ -823,11 +824,13 @@ class GlobalLabelResult(LabelObject, GlobalObject, AnalyzerResult): class FrameValueResult(ValueObject, FramewiseObject, AnalyzerResult): + def _render_plot(self, ax): ax.plot(self.time, self.data) class FrameLabelResult(LabelObject, FramewiseObject, AnalyzerResult): + def _render_plot(self, ax): pass @@ -841,6 +844,7 @@ class EventLabelResult(LabelObject, EventObject, AnalyzerResult): class SegmentValueResult(ValueObject, SegmentObject, AnalyzerResult): + def _render_plot(self, ax): for time, value in (self.time, self.data): ax.axvline(time, ymin=0, ymax=value, color='r') @@ -848,6 +852,7 @@ class SegmentValueResult(ValueObject, SegmentObject, AnalyzerResult): class SegmentLabelResult(LabelObject, SegmentObject, AnalyzerResult): + def _render_plot(self, ax): import itertools colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k']) @@ -855,7 +860,7 @@ class SegmentLabelResult(LabelObject, SegmentObject, AnalyzerResult): for key in self.label_metadata.label.keys(): ax_color[key] = colors.next() for time, duration, label in zip(self.time, self.duration, self.data): - ax.axvspan(time, time+duration, color=ax_color[label], alpha=0.3) + ax.axvspan(time, time + duration, color=ax_color[label], alpha=0.3) class AnalyzerResultContainer(dict): diff --git a/timeside/analyzer/dc.py b/timeside/analyzer/dc.py index 6cf662f..c7c11ff 100644 --- a/timeside/analyzer/dc.py +++ b/timeside/analyzer/dc.py @@ -26,6 +26,7 @@ import numpy class MeanDCShift(Analyzer): + """Mean DC shift analyzer""" implements(IValueAnalyzer) diff --git a/timeside/analyzer/irit_speech_4hz.py b/timeside/analyzer/irit_speech_4hz.py index c04e438..916e55d 100644 --- a/timeside/analyzer/irit_speech_4hz.py +++ b/timeside/analyzer/irit_speech_4hz.py @@ -30,6 +30,7 @@ from scipy.signal import firwin, lfilter class IRITSpeech4Hz(Analyzer): + '''Speech Segmentor based on the 4Hz energy modulation analysis. Properties: @@ -157,7 +158,7 @@ class IRITSpeech4Hz(Analyzer): segs.data_object.time = [(float(s[0]) * self.blocksize() / self.samplerate()) for s in segList] - segs.data_object.duration = [(float(s[1]-s[0]+1) * self.blocksize() / + segs.data_object.duration = [(float(s[1] - s[0] + 1) * self.blocksize() / self.samplerate()) for s in segList] diff --git a/timeside/analyzer/irit_speech_entropy.py b/timeside/analyzer/irit_speech_entropy.py index d8eb045..febf1a4 100644 --- a/timeside/analyzer/irit_speech_entropy.py +++ b/timeside/analyzer/irit_speech_entropy.py @@ -29,6 +29,7 @@ from scipy.ndimage.morphology import binary_opening class IRITSpeechEntropy(Analyzer): + """Speech Segmentor based on Entropy analysis.""" implements(IAnalyzer) @@ -100,7 +101,7 @@ class IRITSpeechEntropy(Analyzer): segs.data_object.time = [(float(s[0]) * self.blocksize() / self.samplerate()) for s in segList] - segs.data_object.duration = [(float(s[1]-s[0]+1) * self.blocksize() / + segs.data_object.duration = [(float(s[1] - s[0] + 1) * self.blocksize() / self.samplerate()) for s in segList] diff --git a/timeside/analyzer/level.py b/timeside/analyzer/level.py index 540cd2f..574f26d 100644 --- a/timeside/analyzer/level.py +++ b/timeside/analyzer/level.py @@ -26,7 +26,9 @@ from timeside.api import IValueAnalyzer import numpy as np from .utils import MACHINE_EPSILON + class Level(Analyzer): + """RMS level analyzer""" implements(IValueAnalyzer) @@ -75,7 +77,8 @@ class Level(Analyzer): if self.max_value == 0: # Prevent np.log10(0) = Inf self.max_value = MACHINE_EPSILON - max_level.data_object.value = np.round(20*np.log10(self.max_value), 3) + max_level.data_object.value = np.round( + 20 * np.log10(self.max_value), 3) self.process_pipe.results.add(max_level) # RMS level @@ -88,5 +91,5 @@ class Level(Analyzer): if rms_val == 0: rms_val = MACHINE_EPSILON - rms_level.data_object.value = np.round(20*np.log10(rms_val), 3) + rms_level.data_object.value = np.round(20 * np.log10(rms_val), 3) self.process_pipe.results.add(rms_level) diff --git a/timeside/analyzer/limsi_sad.py b/timeside/analyzer/limsi_sad.py index 5a5afa0..294d953 100644 --- a/timeside/analyzer/limsi_sad.py +++ b/timeside/analyzer/limsi_sad.py @@ -46,12 +46,13 @@ class GMM: - 2 * N.dot(x, (self.means / self.vars).T) + N.dot(x ** 2, (1.0 / self.vars).T)) + N.log(self.weights) - m = N.amax(llh,1) + m = N.amax(llh, 1) dif = llh - N.atleast_2d(m).T - return m + N.log(N.sum(N.exp(dif),1)) + return m + N.log(N.sum(N.exp(dif), 1)) class LimsiSad(Analyzer): + """ Limsi Speech Activity Detection Systems LimsiSad performs frame level speech activity detection based on GMM models @@ -63,7 +64,6 @@ class LimsiSad(Analyzer): """ implements(IAnalyzer) - def __init__(self, sad_model='etape'): """ Parameters: @@ -77,9 +77,12 @@ class LimsiSad(Analyzer): # 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( + '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 = Yaafe(spec) self.parents.append(parent_analyzer) @@ -92,11 +95,12 @@ class LimsiSad(Analyzer): # load gmm model if sad_model not in ['etape', 'maya']: - raise ValueError("argument sad_model %s not supported. Supported values are 'etape' or 'maya'" % sad_model) - picfname = os.path.join(timeside.__path__[0], 'trained_models', 'limsi_sad_%s.pkl' % sad_model) + raise ValueError( + "argument sad_model %s not supported. Supported values are 'etape' or 'maya'" % sad_model) + picfname = os.path.join( + timeside.__path__[0], 'trained_models', 'limsi_sad_%s.pkl' % sad_model) self.gmms = pickle.load(open(picfname, 'rb')) - @staticmethod @interfacedoc def id(): @@ -115,22 +119,27 @@ class LimsiSad(Analyzer): def process(self, frames, eod=False): if self.input_samplerate != 16000: - raise Exception('%s requires 16000 input sample rate: %d provided' % (self.__class__.__name__, self.input_samplerate)) + raise Exception( + '%s requires 16000 input sample rate: %d provided' % + (self.__class__.__name__, self.input_samplerate)) return frames, eod def post_process(self): mfcc = self.process_pipe.results['yaafe.mfcc']['data_object']['value'] - mfccd1 = self.process_pipe.results['yaafe.mfccd1']['data_object']['value'] - mfccd2 = self.process_pipe.results['yaafe.mfccd2']['data_object']['value'] + mfccd1 = self.process_pipe.results[ + 'yaafe.mfccd1']['data_object']['value'] + mfccd2 = self.process_pipe.results[ + 'yaafe.mfccd2']['data_object']['value'] zcr = self.process_pipe.results['yaafe.zcr']['data_object']['value'] features = N.concatenate((mfcc, mfccd1, mfccd2, zcr), axis=1) - res = 0.5 + 0.5 * (self.gmms[0].llh(features) - self.gmms[1].llh(features)) + res = 0.5 + 0.5 * \ + (self.gmms[0].llh(features) - self.gmms[1].llh(features)) sad_result = self.new_result(data_mode='value', time_mode='framewise') sad_result.id_metadata.id += '.' + 'sad_lhh_diff' - sad_result.id_metadata.name += ' ' + 'Speech Activity Detection Log Likelihood Difference' + sad_result.id_metadata.name += ' ' + \ + 'Speech Activity Detection Log Likelihood Difference' sad_result.data_object.value = res self.process_pipe.results.add(sad_result) - diff --git a/timeside/analyzer/odf.py b/timeside/analyzer/odf.py index c302445..75520ed 100644 --- a/timeside/analyzer/odf.py +++ b/timeside/analyzer/odf.py @@ -29,6 +29,7 @@ from scipy import signal class OnsetDetectionFunction(Analyzer): + """Onset Detection Function analyzer""" implements(IAnalyzer) @@ -77,12 +78,10 @@ class OnsetDetectionFunction(Analyzer): # Low-pass filtering of the spectrogram amplitude along the time axis S = signal.lfilter(signal.hann(15)[8:], 1, abs(spectrogram), axis=0) - import matplotlib.pyplot as plt # plt.figure() # plt.imshow(np.log10(abs(spectrogram)), origin='lower', aspect='auto', interpolation='nearest') - # Clip small value to a minimal threshold np.maximum(S, 1e-9, out=S) diff --git a/timeside/analyzer/preprocessors.py b/timeside/analyzer/preprocessors.py index 324f773..51f89c1 100644 --- a/timeside/analyzer/preprocessors.py +++ b/timeside/analyzer/preprocessors.py @@ -28,6 +28,7 @@ of the analyzer ''' + def downmix_to_mono(process_func): ''' Pre-processing decorator that downmixes frames from multi-channel to mono @@ -160,8 +161,8 @@ def frames_adapter(process_func): if eod and len(eod_list): eod_list[-1] = eod - for index, eod in zip(xrange(0, nb_frames*self.stepsize, self.stepsize), eod_list): - yield (stack[index:index + self.blocksize],eod) + for index, eod in zip(xrange(0, nb_frames * self.stepsize, self.stepsize), eod_list): + yield (stack[index:index + self.blocksize], eod) @functools.wraps(process_func) def wrapper(analyzer, frames, eod): diff --git a/timeside/analyzer/spectrogram.py b/timeside/analyzer/spectrogram.py index 237b2ac..ee70862 100644 --- a/timeside/analyzer/spectrogram.py +++ b/timeside/analyzer/spectrogram.py @@ -27,6 +27,7 @@ import numpy as np class Spectrogram(Analyzer): + """Spectrogram analyzer""" implements(IAnalyzer) @@ -50,7 +51,7 @@ class Spectrogram(Analyzer): def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): super(Spectrogram, self).setup(channels, samplerate, - blocksize, totalframes) + blocksize, totalframes) @staticmethod @interfacedoc diff --git a/timeside/analyzer/utils.py b/timeside/analyzer/utils.py index 6b03306..497126d 100644 --- a/timeside/analyzer/utils.py +++ b/timeside/analyzer/utils.py @@ -23,16 +23,19 @@ import numpy as np MACHINE_EPSILON = np.finfo(np.float32).eps + def downsample_blocking(frames, hop_s, dtype='float32'): # downmixing to one channel if len(frames.shape) != 1: - downsampled = frames.sum(axis = -1) / frames.shape[-1] + downsampled = frames.sum(axis=-1) / frames.shape[-1] else: downsampled = frames # zero padding to have a multiple of hop_s if downsampled.shape[0] % hop_s != 0: - pad_length = hop_s + downsampled.shape[0] / hop_s * hop_s - downsampled.shape[0] - downsampled = np.hstack([downsampled, np.zeros(pad_length, dtype = dtype)]) + pad_length = hop_s + \ + downsampled.shape[0] / hop_s * hop_s - downsampled.shape[0] + downsampled = np.hstack( + [downsampled, np.zeros(pad_length, dtype=dtype)]) # blocking return downsampled.reshape(downsampled.shape[0] / hop_s, hop_s) @@ -53,11 +56,11 @@ def computeModulation(serie, wLen, withLog=True): ''' sLen = len(serie) modul = np.zeros((sLen,)) - w = int(wLen/2) + w = int(wLen / 2) - for i in range(w, sLen-w): + for i in range(w, sLen - w): - d = serie[i-w:i+w] + d = serie[i - w:i + w] if withLog: if not (d > 0).all(): d[d <= 0] = MACHINE_EPSILON # prevent log(0)=inf @@ -66,7 +69,7 @@ def computeModulation(serie, wLen, withLog=True): modul[i] = np.var(d) modul[:w] = modul[w] - modul[-w:] = modul[-w-1] + modul[-w:] = modul[-w - 1] return modul @@ -76,16 +79,16 @@ def segmentFromValues(values, offset=0): ''' - seg = [offset,-1,values[0]] + seg = [offset, -1, values[0]] segList = [] - for i,v in enumerate(values) : + for i, v in enumerate(values): - if not (v == seg[2]) : - seg[1] = i+offset-1 + if not (v == seg[2]): + seg[1] = i + offset - 1 segList.append(tuple(seg)) - seg = [i+offset,-1,v] + seg = [i + offset, -1, v] - seg[1] = i+offset + seg[1] = i + offset segList.append(tuple(seg)) return segList @@ -97,7 +100,7 @@ def segmentFromValues(values, offset=0): # Double emploi avec le calcul mfcc d'aubio. Voir pour la fusion... # Maxime -def melFilterBank(nbFilters,fftLen,sr) : +def melFilterBank(nbFilters, fftLen, sr): ''' Grenerate a Mel Filter-Bank @@ -111,33 +114,33 @@ def melFilterBank(nbFilters,fftLen,sr) : (Use numpy *dot* function). ''' - fh = float(sr)/2.0 - mh = 2595*np.log10(1+fh/700) + fh = float(sr) / 2.0 + mh = 2595 * np.log10(1 + fh / 700) - step = mh/nbFilters; + step = mh / nbFilters - mcenter = np.arange(step,mh,step) + mcenter = np.arange(step, mh, step) - fcenter = 700*(10**(mcenter/2595)-1) + fcenter = 700 * (10 ** (mcenter / 2595) - 1) - filterbank = np.zeros((fftLen,nbFilters)); + filterbank = np.zeros((fftLen, nbFilters)) - for i,_ in enumerate(fcenter) : + for i, _ in enumerate(fcenter): - if i == 0 : + if i == 0: fmin = 0.0 - else : - fmin = fcenter[i-1] + else: + fmin = fcenter[i - 1] - if i == len(fcenter)-1 : + if i == len(fcenter) - 1: fmax = fh - else : - fmax = fcenter[i+1] + else: + fmax = fcenter[i + 1] - imin = np.ceil(fmin/fh*fftLen) - imax = np.ceil(fmax/fh*fftLen) + imin = np.ceil(fmin / fh * fftLen) + imax = np.ceil(fmax / fh * fftLen) - filterbank[imin:imax,i] = triangle(imax-imin) + filterbank[imin:imax, i] = triangle(imax - imin) return filterbank @@ -152,15 +155,15 @@ def triangle(length): - triangle : triangle filter. ''' - triangle = np.zeros((1,length))[0] - climax= np.ceil(length/2) + triangle = np.zeros((1, length))[0] + climax = np.ceil(length / 2) - triangle[0:climax] = np.linspace(0,1,climax) - triangle[climax:length] = np.linspace(1,0,length-climax) + triangle[0:climax] = np.linspace(0, 1, climax) + triangle[climax:length] = np.linspace(1, 0, length - climax) return triangle -def entropy(serie,nbins=10,base=np.exp(1),approach='unbiased'): +def entropy(serie, nbins=10, base=np.exp(1), approach='unbiased'): ''' Compute entropy of a serie using the histogram method. @@ -184,41 +187,39 @@ def entropy(serie,nbins=10,base=np.exp(1),approach='unbiased'): estimate = 0 sigma = 0 - bins,edges = np.histogram(serie,nbins); + bins, edges = np.histogram(serie, nbins) ncell = len(bins) - norm = (np.max(edges)-np.min(edges))/len(bins) - + norm = (np.max(edges) - np.min(edges)) / len(bins) - for b in bins : - if b == 0 : + for b in bins: + if b == 0: logf = 0 - else : + else: logf = np.log(b) - estimate = estimate - b*logf - sigma = sigma + b * logf**2 + estimate = estimate - b * logf + sigma = sigma + b * logf ** 2 count = np.sum(bins) - estimate=estimate/count; - sigma=np.sqrt( (sigma/count-estimate**2)/float(count-1) ); - estimate=estimate+np.log(count)+np.log(norm); - nbias=-(ncell-1)/(2*count); - - if approach =='unbiased' : - estimate=estimate-nbias; - nbias=0; - - elif approach =='mmse' : - estimate=estimate-nbias; - nbias=0; - lambda_value=estimate^2/(estimate^2+sigma^2); - nbias =(1-lambda_value)*estimate; - estimate=lambda_value*estimate; - sigma =lambda_value*sigma; - else : + estimate = estimate / count + sigma = np.sqrt((sigma / count - estimate ** 2) / float(count - 1)) + estimate = estimate + np.log(count) + np.log(norm) + nbias = -(ncell - 1) / (2 * count) + + if approach == 'unbiased': + estimate = estimate - nbias + nbias = 0 + + elif approach == 'mmse': + estimate = estimate - nbias + nbias = 0 + lambda_value = estimate ^ 2 / (estimate ^ 2 + sigma ^ 2) + nbias = (1 - lambda_value) * estimate + estimate = lambda_value * estimate + sigma = lambda_value * sigma + else: return 0 - estimate=estimate/np.log(base); - nbias =nbias /np.log(base); - sigma =sigma /np.log(base); + estimate = estimate / np.log(base) + nbias = nbias / np.log(base) + sigma = sigma / np.log(base) return estimate - diff --git a/timeside/analyzer/vamp_plugin.py b/timeside/analyzer/vamp_plugin.py index 88f3ef0..0ce4ed1 100644 --- a/timeside/analyzer/vamp_plugin.py +++ b/timeside/analyzer/vamp_plugin.py @@ -28,6 +28,7 @@ import numpy as np class VampSimpleHost(Analyzer): + """Vamp plugins library interface analyzer""" implements(IAnalyzer) @@ -78,16 +79,17 @@ class VampSimpleHost(Analyzer): return if duration is not None: - plugin_res = self.new_result(data_mode='value', time_mode='segment') + plugin_res = self.new_result( + data_mode='value', time_mode='segment') plugin_res.data_object.duration = duration else: - plugin_res = self.new_result(data_mode='value', time_mode='event') + plugin_res = self.new_result( + data_mode='value', time_mode='event') plugin_res.data_object.time = time plugin_res.data_object.value = value - -# # Fix strat, duration issues if audio is a segment +# Fix strat, duration issues if audio is a segment # if self.mediainfo()['is_segment']: # start_index = np.floor(self.mediainfo()['start'] * # self.result_samplerate / @@ -107,7 +109,6 @@ class VampSimpleHost(Analyzer): # plugin_res.audio_metadata.duration = fixed_duration # # value = value[start_index:stop_index + 1] - plugin_res.id_metadata.id += '.' + '.'.join(plugin_line[1:]) plugin_res.id_metadata.name += ' ' + \ ' '.join(plugin_line[1:]) @@ -139,7 +140,8 @@ class VampSimpleHost(Analyzer): stepsize = int(m.groups()[1]) # Get the results - value = np.asfarray([line.split(': ')[1].split(' ') for line in res if (len(line.split(': ')) > 1)]) + value = np.asfarray([line.split(': ')[1].split(' ') + for line in res if (len(line.split(': ')) > 1)]) time = np.asfarray([r.split(':')[0].split(',')[0] for r in res]) time_len = len(res[0].split(':')[0].split(',')) @@ -148,7 +150,8 @@ class VampSimpleHost(Analyzer): duration = None elif time_len == 2: # segment - duration = np.asfarray([r.split(':')[0].split(',')[1] for r in res]) + duration = np.asfarray( + [r.split(':')[0].split(',')[1] for r in res]) return (time, duration, value) diff --git a/timeside/analyzer/waveform.py b/timeside/analyzer/waveform.py index e5eb478..b5fdbd1 100644 --- a/timeside/analyzer/waveform.py +++ b/timeside/analyzer/waveform.py @@ -26,7 +26,9 @@ import numpy as np from preprocessors import downmix_to_mono, frames_adapter + class Waveform(Analyzer): + """Waveform analyzer""" implements(IAnalyzer) # TODO check if needed with inheritance @@ -39,7 +41,7 @@ class Waveform(Analyzer): def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): super(Waveform, self).setup(channels, samplerate, - blocksize, totalframes) + blocksize, totalframes) self.values = [] self.result_blocksize = 1 self.result_stepsize = 1 diff --git a/timeside/analyzer/yaafe.py b/timeside/analyzer/yaafe.py index 1a3fa2c..7024c46 100644 --- a/timeside/analyzer/yaafe.py +++ b/timeside/analyzer/yaafe.py @@ -35,17 +35,19 @@ from timeside.analyzer.preprocessors import downmix_to_mono class Yaafe(Analyzer): + """Yaafe feature extraction library interface analyzer""" implements(IAnalyzer) def __init__(self, yaafeSpecification=None): - super(Yaafe,self).__init__() + super(Yaafe, self).__init__() # Check arguments if yaafeSpecification is None: yaafeSpecification = FeaturePlan(sample_rate=32000) # add feature definitions manually - yaafeSpecification.addFeature('mfcc: MFCC blockSize=512 stepSize=256') + yaafeSpecification.addFeature( + 'mfcc: MFCC blockSize=512 stepSize=256') if isinstance(yaafeSpecification, DataFlow): self.dataFlow = yaafeSpecification @@ -59,7 +61,6 @@ class Yaafe(Analyzer): str(FeaturePlan))) self.yaafe_engine = None - @interfacedoc def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): @@ -91,7 +92,7 @@ class Yaafe(Analyzer): # do process things... # Convert to float64and reshape # for compatibility with Yaafe engine - yaafe_frames = frames.astype(numpy.float64).reshape(1,-1) + yaafe_frames = frames.astype(numpy.float64).reshape(1, -1) # write audio array on 'audio' input self.yaafe_engine.writeInput('audio', yaafe_frames) -- 2.39.5