IOFormat.cpp

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_IOFormat_cpp)
00056 #define ALIZE_IOFormat_cpp
00057 
00058 #include <iostream>
00059 #include <fstream>  // pour outFile
00060 #include <cstdio>   // pour printf()
00061 #include <cassert> // pour le debug pratique
00062 #include <cmath>
00063 #include <liatools.h>
00064 #include "IOFormat.h"
00065 
00066 //******************************************************
00067 // These functions are used to ouput Objects into a vector
00068 //******************************************************
00069 //------------------------------------------------------------------------
00070 // Output Weight part of fisher kernel -- Nicolas SCHEFFER (deprecated)
00071 void outputWeightVector(MixtureGD& world,MixtureGD& clientMixture, double frameCount, Config& config) {
00072   String fileName=config.getParam("vectorFilesPath")+clientMixture.getId()+config.getParam("vectorFilesExtension");
00073   if (verbose) cerr << "Output Weights Transformation Parameters to:" << fileName << endl;
00074   double w,c,feat;
00075   ofstream paramFile(fileName.c_str());
00076   for (unsigned long i=0;i<world.getDistribCount();i++) {
00077     w=world.weight(i);
00078     c=clientMixture.weight(i);
00079     feat=c/sqrt(w);
00080     paramFile << feat << " ";
00081   }
00082 paramFile << endl;
00083 paramFile.close();
00084 }
00085 
00086 // Output in SVMLight Format -- Nicolas SCHEFFER
00087 void outputSVMLightVector(RealVector<double>&v, const String &id, Config& config) {
00088   String fileName=config.getParam("vectorFilesPath")+id+config.getParam("vectorFilesExtension");
00089   ofstream paramFile(fileName.c_str());
00090   paramFile << "1 ";
00091   for (unsigned long i=0;i<v.size();i++) 
00092     paramFile <<i+1<< ":" << v[i] << " ";
00093 paramFile << endl;
00094 paramFile.close();
00095 }
00096 
00097 //------------------------------------------------------------------------
00098 // Output Matrix in SVMLight Format
00099 void outputDSM(DoubleSquareMatrix & W,MixtureGD& clientMixture,Config& config) {
00100   String fileName=config.getParam("vectorFilesPath")+clientMixture.getId()+config.getParam("vectorFilesExtension");
00101   if (verbose) cout << "Output MLLR Matrix to:" << fileName << endl;
00102   ofstream out(fileName.c_str());
00103   for (unsigned long i=0;i<W.size()-1;i++)
00104       for (unsigned long j=0;j<W.size();j++)
00105         out << W(i,j) << " ";
00106   out << endl;
00107   out.close();
00108 }
00109 //******************************************************
00110 // These functions are related to file format
00111 //******************************************************
00112 void outputResultLine(double LLR, const String & clientName, const String & seg, const String &gender, int decision, ostream& strm)
00113 {
00114   strm << gender<<" "<<clientName<<" "<< decision <<" "<<seg <<" "<< LLR << endl;
00115 }
00116 
00117 void outputResultLine(double LLR, const String & clientName, const String & seg,real_t begin,real_t end, const String &gender, int decision, ostream& strm)
00118 {
00119   strm << gender<< " "<<clientName<<" "<< decision <<" "<<seg <<" "<< begin << " "<< end<< " "<< LLR << endl;
00120 }
00121 
00122 //-------------------------------------------------------------------------
00123 //Output a result line in a file in LIA format: F client 1 test 0 20 -0.02
00124 void outputResultLIARALLine(const String &gender, const String & clientName, const String & channel, const String & seg, const String & start, const String & duration, double LLR, ostream& strm)
00125 {
00126         strm <<gender<<" "<<clientName<<" "<<channel<<" "<<seg<<" "<<start<<" "<<duration<<" "<<LLR<< endl;
00127 }
00128 
00129 //-------------------------------------------------------------------------
00130 //Output a result line in NIST SRE 2004 format
00131 void outputResultNIST04Line(const String &trainTypeTest, const String &adaptationMode, const String &segTypeTest, const String &gender, const String & clientName, const String & seg, const String &decision, double LLR, ostream& strm)
00132 {
00133         strm <<trainTypeTest<<" "<<adaptationMode<<" "<<segTypeTest<<" "<<gender<<" "<<clientName<<" "<<seg<<" "<<decision<<" "<<LLR<< endl;
00134 }
00135 
00136 //-------------------------------------------------------------------------
00137 //Output a result line in ETF format
00138 void outputResultETFLine(const String &source, const String &channel, const String &start, double duration, const String &type, const String &sub, const String &event, double score, const String &decision, ostream& strm)
00139 {
00140         strm <<source<< " "<<channel<<" "<<start<<" "<<duration<<" "<<type<< " "<<sub<< " "<<event<<" "<<score<<" "<<decision<<endl;
00141 }
00142 
00143 //-------------------------------------------------------------------------
00144 //Output a result line in MDTM format
00145 void outputResultMDTMLine(const String &source, const String &channel, const String &start, double duration, const String &type, double conf, const String &sub, ostream& strm)
00146 {
00147         strm <<source<< " "<<channel<<" "<<start<<" "<<duration<<" "<<type<< " "<<conf<< " "<<sub<<endl;
00148 }
00149 
00150 //-------------------------------------------------------------------------------------------------------
00151 // Affect the fields values depending on the format
00152 //-------------------------------------------------------------------------------------------------------
00153 
00154 // Return LIA info fields
00155 void setLIAInfoFields(unsigned long & genderField, unsigned long & nameField, unsigned long & decisionField, unsigned long & segField, unsigned long & scoreField)
00156 {
00157         genderField=0;
00158         nameField=1;
00159         decisionField=2;
00160         segField=3;
00161         scoreField=4;
00162 }
00163 
00164 // Return NIST info fields
00165 void setNIST04InfoFields(unsigned long & genderField, unsigned long & nameField, unsigned long & decisionField, unsigned long & segField, unsigned long & scoreField)
00166 {
00167         genderField=3;
00168         nameField=4;
00169         decisionField=6;
00170         segField=5;
00171         scoreField=7;
00172 }
00173 
00174 
00175 #endif //!defined(ALIZE_IOFormat_cpp)