from level import *
from dc import *
-from aubio_temporal import *
-from aubio_pitch import *
-from aubio_mfcc import *
-from aubio_melenergy import *
-from aubio_specdesc import *
+#~ from aubio_temporal import *
+#~ from aubio_pitch import *
+#~ from aubio_mfcc import *
+#~ from aubio_melenergy import *
+#~ from aubio_specdesc import *
from yaafe import * # TF : add Yaafe analyzer
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 irit_monopoly import IRITMonopoly
from irit_diverg import IRITDiverg
-
+from irit_music_SLN import IRITMusicSLN
+from irit_music_SNB import IRITMusicSNB
+#~ from irit_monopoly import IRITMonopoly
from odf import OnsetDetectionFunction
return (2*modeleCourt.erreur_residuelle*modeleLong.erreur_residuelle/modeleLong.variance_erreur_residuelle-(1.0+QV)*modeleLong.erreur_residuelle**2/modeleLong.variance_erreur_residuelle+QV-1.0)/(2.0*QV)
-def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,seuil_vois=None,withTrace = False):
+def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True):
'''
Fonction principale de segmentation.
- lamb (float) : valeur de lambda pour la détection de chute de Wn. Par défaut = 40.0
- biais (float) : valeur du bias à appliquer (en négatif). Par défaut = -0.2
- with_backward (Bool) : Interrupteur du calcul ou non en backward. Par défaut = True
- - seuil_vois (float) : Si fixé, défini les valeurs de lambda et du biais en fonction du voisement ou non du buffer initial du model court terme.
- (voisement_yin > seuil_vois ==> Non voisé). Par défaut = None
- - withTrace (Bool) : Enregistre ou non la trace de tous les calculs pour un affichage à postériori. Par défaut = False
'''
# Initialisation
# Recherche de nouveau maximum
if Wn > maxi[0] :
maxi = (Wn,t)
-
- if withTrace :
- dynaWn += [Wn]
- tWn += [t]
# Recherche de rupture par chute superieure à lambda
if (maxi[0] - Wn) > lamb :
# Si une rupture à été detecté avec un modèle stable (Wn à croit)
if t_rupt > -1 :
- m = 'forward'
+ m = 1
if with_backward :
bdata = data[t_rupt:rupt_last:-1]
if len(bdata) > 0 :
- front = segment(bdata,fe,ordre,float(Lmin)/fe,lamb,biais,with_backward=False,seuil_vois=seuil_vois,withTrace=withTrace)
+ front = segment(bdata,fe,ordre,float(Lmin)/fe,lamb,biais,with_backward=False)
t_bs = [ t_rupt-tr for tr,_ in front]
if len(t_bs) > 0 :
t_rupt = t_bs[-1]
- m ='backward'
+ m =-1
# Sinon on crée un segment de longueur minimale
else :
t_rupt = rupt_last+Lmin
- m = 'instable'
+ m = 0
- if withTrace :
- evnt['selected'] = t_rupt
- evnt['comment'] = m
- trace+=[evnt]
-
# Mise à jour des frontières
t = t_rupt
rupt_last = t_rupt
class IRITDiverg(Analyzer):
implements(IAnalyzer)
'''
+
+
'''
+
def __init__(self, blocksize=1024, stepsize=None) :
super(IRITDiverg, self).__init__();
self.parents.append(Waveform())
@interfacedoc
def setup(self, channels=None, samplerate=None,blocksize=None, totalframes=None):
- super(IRITDiverg, self).setup(channels,
- samplerate,
- blocksize,
- totalframes)
- self.parents.append(Waveform())
+ super(IRITDiverg, self).setup(channels,samplerate,blocksize,totalframes)
+
@staticmethod
@interfacedoc
def id():
return frames, eod
def post_process(self):
- data = self.process_pipe.results['waveform_analyzer'].data
+ data = list(self.process_pipe.results['waveform_analyzer'].data)
frontieres = segment(data,self.samplerate(),self.ordre)
- f = open('front.lab','w')
- for t,m in frontieres :
- f.write('%f\t%s\n'%(float(t)/self.samplerate(),m));
- f.close()
- print frontieres
+
+
+ segs = self.new_result(data_mode='label', time_mode='event')
+ segs.id_metadata.id += '.' + 'segments'
+ segs.id_metadata.name += ' ' + 'Segments'
+
+ label = {0: 'Instable', 1: 'Forward', -1: 'Backward'}
+ segs.label_metadata.label = label
+
+ segs.data_object.label = [s[1] for s in frontieres]
+ segs.data_object.time = [(float(s[0]) / self.samplerate()) for s in frontieres]
+ self.process_pipe.results.add(segs)
+ return
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# 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: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+class IRITMusicLDN(Analyzer):
+ implements(IAnalyzer)
+
+ def __init__(self, blocksize=1024, stepsize=None) :
+ super(IRITMusicLDN, self).__init__();
+ self.parents.append(IRITDiverg())
+ self.wLen = 1.0
+ self.wStep = 0.1
+ self.threshold = 20
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "irit_music_sln"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "IRIT Music Detector - Segment Length"
+
+ @staticmethod
+ @interfacedoc
+ def unit():
+ return ""
+
+ def __str__(self):
+ return "Music confidence indexes"
+
+ def process(self, frames, eod=False):
+
+ return frames,eod
+
+
+ def post_process(self):
+ '''
+
+ '''
+
+ segList = self.process_pipe.results['irit_diverg.segments'].time
+ w = self.wLen/ 2;
+ end = segList[-1]
+ tLine = arange(0,end,self.wStep)
+
+ segLen = array([0]*len(tLine))
+
+ for i,t in enumerate(tLine):
+ idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+ segLen[i]= len(idx)
+
+
+ plot(tLine,segLen)
+ show()
+ # Confidence Index
+ conf = array(segLen - self.threshold) / self.threshold
+ conf[conf > 1] = 1
+
+ segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+ segLenRes.id_metadata.id += '.' + 'energy_confidence'
+ segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+ segLenRes.data_object.value = segLen
+
+ self.process_pipe.results.add(segLenRes)
+
+ # Segment
+ convert = {False: 0, True: 1}
+ label = {0: 'nonMusic', 1: 'Music'}
+
+ segList = segmentFromValues(segLen > self.threshold)
+ # Hint : Median filtering could imrove smoothness of the result
+ # from scipy.signal import medfilt
+ # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+ segs = self.new_result(data_mode='label', time_mode='segment')
+ segs.id_metadata.id += '.' + 'segments'
+ segs.id_metadata.name += ' ' + 'Segments'
+
+ segs.label_metadata.label = label
+
+ segs.data_object.label = [convert[s[2]] for s in segList]
+ segs.data_object.time = [tLine[s[0]] for s in segList]
+ segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+ self.process_pipe.results.add(segs)
+ return
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# 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: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+
+class IRITMusicSLN(Analyzer):
+ implements(IAnalyzer)
+
+ def __init__(self, blocksize=1024, stepsize=None) :
+ super(IRITMusicSLN, self).__init__();
+ self.parents.append(IRITDiverg())
+ self.wLen = 1.0
+ self.wStep = 0.1
+ self.threshold = 20
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "irit_music_sln"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "IRIT Music Detector - Segment Length"
+
+ @staticmethod
+ @interfacedoc
+ def unit():
+ return ""
+
+ def __str__(self):
+ return "Music confidence indexes"
+
+ def process(self, frames, eod=False):
+
+ return frames,eod
+
+
+ def post_process(self):
+ '''
+
+ '''
+
+ segList = self.process_pipe.results['irit_diverg.segments'].time
+ w = self.wLen/ 2;
+ end = segList[-1]
+ tLine = arange(0,end,self.wStep)
+
+ segLen = array([0]*len(tLine))
+
+ for i,t in enumerate(tLine):
+ idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+ segLen[i]= len(idx)
+
+
+ plot(tLine,segLen)
+ show()
+ # Confidence Index
+ conf = array(segLen - self.threshold) / self.threshold
+ conf[conf > 1] = 1
+
+ segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+ segLenRes.id_metadata.id += '.' + 'energy_confidence'
+ segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+ segLenRes.data_object.value = segLen
+
+ self.process_pipe.results.add(segLenRes)
+
+ # Segment
+ convert = {False: 0, True: 1}
+ label = {0: 'nonMusic', 1: 'Music'}
+
+ segList = segmentFromValues(segLen > self.threshold)
+ # Hint : Median filtering could imrove smoothness of the result
+ # from scipy.signal import medfilt
+ # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+ segs = self.new_result(data_mode='label', time_mode='segment')
+ segs.id_metadata.id += '.' + 'segments'
+ segs.id_metadata.name += ' ' + 'Segments'
+
+ segs.label_metadata.label = label
+
+ segs.data_object.label = [convert[s[2]] for s in segList]
+ segs.data_object.time = [tLine[s[0]] for s in segList]
+ segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+ self.process_pipe.results.add(segs)
+ return
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# 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: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+
+class IRITMusicSNB(Analyzer):
+ implements(IAnalyzer)
+
+ def __init__(self, blocksize=1024, stepsize=None) :
+ super(IRITMusicSNB, self).__init__();
+ self.parents.append(IRITDiverg())
+ self.wLen = 1.0
+ self.wStep = 0.1
+ self.threshold = 20
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "irit_music_snb"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "IRIT Music Detector - Segment Number"
+
+ @staticmethod
+ @interfacedoc
+ def unit():
+ return ""
+
+ def __str__(self):
+ return "Music confidence indexes"
+
+ def process(self, frames, eod=False):
+
+ return frames,eod
+
+
+ def post_process(self):
+ '''
+
+ '''
+
+ segList = self.process_pipe.results['irit_diverg.segments'].time
+ w = self.wLen/ 2;
+ end = segList[-1]
+ tLine = arange(0,end,self.wStep)
+
+ segLen = array([0]*len(tLine))
+
+ for i,t in enumerate(tLine):
+ idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+ l = [tLine[t1]-tLine[t2] for t1,t2 in zip()]
+ segLen[i]= len(idx)
+
+
+ plot(tLine,segLen)
+ show()
+ # Confidence Index
+ conf = array(segLen - self.threshold) / self.threshold
+ conf[conf > 1] = 1
+
+ segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+ segLenRes.id_metadata.id += '.' + 'energy_confidence'
+ segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+ segLenRes.data_object.value = segLen
+
+ self.process_pipe.results.add(segLenRes)
+
+ # Segment
+ convert = {False: 0, True: 1}
+ label = {0: 'nonMusic', 1: 'Music'}
+
+ segList = segmentFromValues(segLen > self.threshold)
+ # Hint : Median filtering could imrove smoothness of the result
+ # from scipy.signal import medfilt
+ # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+ segs = self.new_result(data_mode='label', time_mode='segment')
+ segs.id_metadata.id += '.' + 'segments'
+ segs.id_metadata.name += ' ' + 'Segments'
+
+ segs.label_metadata.label = label
+
+ segs.data_object.label = [convert[s[2]] for s in segList]
+ segs.data_object.time = [tLine[s[0]] for s in segList]
+ segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+ self.process_pipe.results.add(segs)
+ return