SequenceExtractor.h

Go to the documentation of this file.
00001 /*
00002 This file is part of LIA_RAL which is a set of software based on ALIZE
00003 toolkit for speaker recognition. ALIZE toolkit is required to use LIA_RAL.
00004 
00005 LIA_RAL project is a development project was initiated by the computer
00006 science laboratory of Avignon / France (Laboratoire Informatique d'Avignon -
00007 LIA) [http://lia.univ-avignon.fr <http://lia.univ-avignon.fr/>]. Then it
00008 was supported by two national projects of the French Research Ministry:
00009         - TECHNOLANGUE program [http://www.technolangue.net]
00010         - MISTRAL program [http://mistral.univ-avignon.fr]
00011 
00012 LIA_RAL is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation, either version 3 of
00015 the License, or any later version.
00016 
00017 LIA_RAL is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021 
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with LIA_RAL.
00024 If not, see [http://www.gnu.org/licenses/].
00025 
00026 The LIA team as well as the LIA_RAL project team wants to highlight the
00027 limits of voice authentication in a forensic context.
00028 The "Person Authentification by Voice: A Need of Caution" paper
00029 proposes a good overview of this point (cf. "Person
00030 Authentification by Voice: A Need of Caution", Bonastre J.F.,
00031 Bimbot F., Boe L.J., Campbell J.P., Douglas D.A., Magrin-
00032 chagnolleau I., Eurospeech 2003, Genova].
00033 The conclusion of the paper of the paper is proposed bellow:
00034 [Currently, it is not possible to completely determine whether the
00035 similarity between two recordings is due to the speaker or to other
00036 factors, especially when: (a) the speaker does not cooperate, (b) there
00037 is no control over recording equipment, (c) recording conditions are not
00038 known, (d) one does not know whether the voice was disguised and, to a
00039 lesser extent, (e) the linguistic content of the message is not
00040 controlled. Caution and judgment must be exercised when applying speaker
00041 recognition techniques, whether human or automatic, to account for these
00042 uncontrolled factors. Under more constrained or calibrated situations,
00043 or as an aid for investigative purposes, judicious application of these
00044 techniques may be suitable, provided they are not considered as infallible.
00045 At the present time, there is no scientific process that enables one to
00046 uniquely characterize a persones voice or to identify with absolute
00047 certainty an individual from his or her voice.]
00048 
00049 Copyright (C) 2004-2010
00050 Laboratoire d'informatique d'Avignon [http://lia.univ-avignon.fr]
00051 LIA_RAL admin [alize@univ-avignon.fr]
00052 Jean-Francois Bonastre [jean-francois.bonastre@univ-avignon.fr]
00053 */
00054 
00055 #if !defined(ALIZE_SequenceExtractor_h)
00056 #define ALIZE_SequenceExtractor_h
00057 
00058 #include "alize.h"
00059 #include "LabelNGram.h"
00060 #include "BNgram.h"
00061 
00062 class SymbTab{
00063   short int _nbSymb;
00064   bool *_symbTab;
00065  public:
00066   void init(bool val=false){for (int i=0;i<_nbSymb;_symbTab[i++]=val);}
00067   void reserveMem();
00068   void setNbSymb(short int nbSymb){_nbSymb=nbSymb;}
00069   SymbTab(short int nbSymb){_nbSymb=nbSymb;reserveMem();init(false);}
00070   SymbTab(){_nbSymb=0;_symbTab=NULL;}
00071   SymbTab(const SymbTab &);
00072   ~SymbTab(){if (_symbTab!=NULL) delete [] _symbTab;};
00073   SymbTab& operator =(const SymbTab & symbTab);
00074   bool operator==(const SymbTab &);
00075   bool operator!=(const SymbTab &);
00076   bool isIn(short int symb);
00077   void setSymb(short int symb);
00078   short int getNbSymb(){return _nbSymb;}
00079   void show();
00080 };
00081 
00082 class ReadMemory{
00083   ifstream _inputFile;
00084   unsigned long _idx;
00085   unsigned long _realIdx;
00086   short int *_buf;
00087   int _bufSize;
00088   unsigned long _begin;
00089   unsigned long _length;
00090   bool _segmental;
00091   bool readSymb(short int &, string &);
00092 public:
00093   ReadMemory(String,int,unsigned long,unsigned long);
00094   ~ReadMemory();
00095   bool notEof();
00096   bool eof();
00097   bool lecture(bool);
00098   unsigned long getIdx();
00099   short int getCurrentSymb();
00100   void setIdx(unsigned long idx);
00101 };
00102 
00103 class Seq{
00104   short int _maxLength;
00105   short int _length;
00106   short int _nbInputSymb;
00107   SymbTab *_array;
00108   void _reserveMem();
00109  public:
00110   Seq(short int,short int);
00111   Seq(const Seq&);
00112   ~Seq();
00113   Seq & operator=(const Seq &);
00114   SymbTab &operator[](short int);
00115   void setLength(short int order);
00116   short int getLength();
00117   void init(short int);
00118   void show();
00119   void add(SymbTab *ptr);
00120  
00121 };
00122 
00123 struct CommonPartTreeNode{
00124   short int symb; 
00125   unsigned long count;
00126   unsigned long totalChildCount;
00127   CommonPartTreeNode *ch;
00128   CommonPartTreeNode *br;
00129 };
00130 class CommonPartTree{
00131   CommonPartTreeNode * _seed;
00132   unsigned long _totalCount;
00133   unsigned long _totalChildCount;
00134   void _freeTree(CommonPartTreeNode* seed);
00135   CommonPartTreeNode* _newNode(const short int symb,const unsigned long count,CommonPartTreeNode *ch,CommonPartTreeNode *br);
00136   CommonPartTreeNode* _findInsert(const short int symb,unsigned long count,CommonPartTreeNode * ptr);
00137   unsigned long _findMaxSeq(CommonPartTreeNode *ptr,Seq &seq, short int &);
00138   CommonPartTreeNode* _suppressSeq(CommonPartTreeNode * ptr,Seq &seq,
00139                                   short int order, unsigned long &childCountDelta);
00140   void _show(CommonPartTreeNode *ptr,unsigned long order);
00141   CommonPartTreeNode* _findPartSeq(Seq &,short int,CommonPartTreeNode *);
00142   public:
00143   CommonPartTree();
00144   CommonPartTree(const CommonPartTree &);
00145   CommonPartTree operator =(const CommonPartTree &);
00146   ~CommonPartTree();
00147   void addNGram(NGram& nGram);
00148   unsigned long findMaxSeq(Seq&);
00149   unsigned long findMaxEndSeq(Seq&);
00150   void suppressSeq(Seq &seq);
00151   unsigned long getTotalChildCount(){return _totalChildCount;}
00152   void setTotalCount(unsigned long total){_totalCount=total;}
00153   unsigned long getTotalCount(){return _totalCount;}
00154   void show();
00155 };
00156 
00157 
00158 
00159 struct SequenceDecoderNode{
00160   SymbTab *symbTab;
00161   short int outputSymb;
00162   SequenceDecoderNode *ch;
00163   SequenceDecoderNode *br;
00164 };
00165 
00166 class SequenceDecoder{
00167   short int _nbInputSymb;          // Number of input symbols, i.e. number of gaussian index
00168   unsigned long _nbOutputSeqPart;  // Current number of detected sequences (part of output seq)
00169   unsigned long _nbOutputSeq;      // Nb of different output symbols in the tree
00170   SequenceDecoderNode *_seed;
00171   void _freeTree(SequenceDecoderNode* seed);
00172   SequenceDecoderNode* _newNode(const SymbTab &symbTab,const short int outputSymb,SequenceDecoderNode *ch,SequenceDecoderNode *br);
00173   SequenceDecoderNode* _findInsert(const SymbTab &symbTab,SequenceDecoderNode *ptr);
00174   void _show(SequenceDecoderNode *,short int);
00175   void _toFile(SequenceDecoderNode *,short int,Seq &,ostream &);
00176   void _save(SequenceDecoderNode *,ostream & );
00177   SequenceDecoderNode *_load(istream &);
00178   bool _decode(SequenceDecoderNode *ptr,ReadMemory & inp,ostream & outputFile,unsigned long &begin,short int &);
00179  public:
00180   SequenceDecoder(short int);
00181   SequenceDecoder(const SequenceDecoder &);
00182   SequenceDecoder operator =(const SequenceDecoder &);
00183   ~SequenceDecoder();
00184   short int getNbInputSymb(){return _nbInputSymb;}
00185   short int getNbOutputSeq(){return (short)_nbOutputSeq;}
00186   void setNbOutputSeq(unsigned long nb){_nbOutputSeq=nb;}
00187   unsigned long getNbOutputSeqPart(){return _nbOutputSeqPart;}
00188   void addSequence(Seq &, const short int);
00189   void show();
00190   void toFile(ostream &);
00191   void save(ostream &);
00192   void load(istream &);
00193   void decode(String,ostream &,unsigned long,unsigned long,bool,bool,BNgram &); 
00194 };  
00195 
00196 // main functions
00197 int sequenceExtractor(alize::Config&);
00198 int sequenceDecoder(alize::Config &);
00199 
00200 #endif //