From: Thomas Fillon Date: Tue, 21 Oct 2014 18:38:27 +0000 (+0200) Subject: fix numpy related bug and minor updates in irit_speech_4hz analyzer X-Git-Tag: 0.6~4^2~7 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=bd20eeb726798f92967ba93d8b64eb9e420b6bff;p=timeside.git fix numpy related bug and minor updates in irit_speech_4hz analyzer --- diff --git a/timeside/analyzer/irit_speech_4hz.py b/timeside/analyzer/irit_speech_4hz.py index ecd04d0..dd24bf2 100644 --- a/timeside/analyzer/irit_speech_4hz.py +++ b/timeside/analyzer/irit_speech_4hz.py @@ -24,12 +24,12 @@ from timeside.analyzer.core import Analyzer from timeside.analyzer.utils import melFilterBank, computeModulation from timeside.analyzer.utils import segmentFromValues from timeside.api import IAnalyzer -from numpy import array, hamming, dot, mean, float, mod +import numpy as np from numpy.fft import rfft from scipy.signal import firwin, lfilter from timeside.analyzer.preprocessors import frames_adapter -from ..tools.parameters import Float, HasTraits +from timeside.tools.parameters import Float, HasTraits class IRITSpeech4Hz(Analyzer): @@ -114,11 +114,11 @@ class IRITSpeech4Hz(Analyzer): frames = frames.T[0] # windowing of the frame (could be a changeable property) - w = frames * hamming(len(frames)) + w = frames * np.hamming(len(frames)) # Mel scale spectrum extraction f = abs(rfft(w, n=2 * self.nFFT)[0:self.nFFT]) - e = dot(f ** 2, self.melFilter) + e = np.dot(f ** 2, self.melFilter) self.energy4hz.append(e) @@ -135,13 +135,13 @@ class IRITSpeech4Hz(Analyzer): num = firwin(self.orderFilter, Wn, pass_zero=False) # Energy on the frequency range - self.energy4hz = array(self.energy4hz) + self.energy4hz = np.array(self.energy4hz) energy = lfilter(num, 1, self.energy4hz.T, 0) energy = sum(energy) # Normalization if self.normalizeEnergy and energy.any(): - energy = energy / mean(energy) + energy = energy / np.mean(energy) # Energy Modulation frameLenModulation = int( @@ -149,7 +149,7 @@ class IRITSpeech4Hz(Analyzer): modEnergyValue = computeModulation(energy, frameLenModulation, True) # Confidence Index - conf = array(modEnergyValue - self.threshold) / self.threshold + conf = np.array(modEnergyValue - self.threshold) / self.threshold conf[conf > 1] = 1 modEnergy = self.new_result(data_mode='value', time_mode='framewise') @@ -167,11 +167,11 @@ class IRITSpeech4Hz(Analyzer): decision = modEnergyValue > self.threshold segList = segmentFromValues(decision) - # Hint : Median filtering could imrove smoothness of the result + # Hint : Median filtering could improve smoothness of the result from scipy.signal import medfilt - output_samplerate = float(self.samplerate()) / self.input_stepsize - N = self.medfilt_duration * output_samplerate - N += 1 - mod(N, 2) # Make N odd + output_samplerate = np.float(self.samplerate()) / self.input_stepsize + N = int(np.ceil(self.medfilt_duration * output_samplerate)) + N += 1 - np.mod(N, 2) # Make N odd segList_filt = segmentFromValues(medfilt(decision, N)) segs = self.new_result(data_mode='label', time_mode='segment') @@ -181,10 +181,10 @@ class IRITSpeech4Hz(Analyzer): segs.data_object.label_metadata.label = label segs.data_object.label = [convert[s[2]] for s in segList] - segs.data_object.time = [(float(s[0]) * self.blocksize() / + segs.data_object.time = [(np.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 = [(np.float(s[1] - s[0] + 1) * self.blocksize() / self.samplerate()) for s in segList] @@ -198,10 +198,10 @@ class IRITSpeech4Hz(Analyzer): segs.data_object.label_metadata.label = label segs.data_object.label = [convert[s[2]] for s in segList_filt] - segs.data_object.time = [(float(s[0]) * self.blocksize() / + segs.data_object.time = [(np.float(s[0]) * self.blocksize() / self.samplerate()) for s in segList_filt] - segs.data_object.duration = [(float(s[1] - s[0] + 1) * self.blocksize() / + segs.data_object.duration = [(np.float(s[1] - s[0] + 1) * self.blocksize() / self.samplerate()) for s in segList_filt]