⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcmap.c

📁 该压缩包为最新版htk的源代码,htk是现在比较流行的语音处理软件,请有兴趣的朋友下载使用
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ----------------------------------------------------------- *//*                                                             *//*                          ___                                *//*                       |_| | |_/   SPEECH                    *//*                       | | | | \   RECOGNITION               *//*                       =========   SOFTWARE                  */ /*                                                             *//*                                                             *//* ----------------------------------------------------------- *//* developed at:                                               *//*                                                             *//*      Speech Vision and Robotics group                       *//*      Cambridge University Engineering Department            *//*      http://svr-www.eng.cam.ac.uk/                          *//*                                                             *//* main authors: Valtcho Valtchev, Steve Young,                *//*               Julian Odell, Gareth Moore                    *//* ----------------------------------------------------------- *//*         Copyright:                                          *//*                                                             *//*          1994-2002 Cambridge University                     *//*                    Engineering Department                   *//*                                                             *//*   Use of this software is governed by a License Agreement   *//*    ** See the file License for the Conditions of Use  **    *//*    **     This banner notice must not be removed      **    *//*                                                             *//* ----------------------------------------------------------- *//*      File: LCMap:  Class Map Routines                       *//* ----------------------------------------------------------- */char *lcmap_version = "!HVER!LCMap:   3.3 [CUED 28/04/05]";char *lcmap_vc_id = "$Id: LCMap.c,v 1.1.1.1 2005/05/12 10:52:17 jal58 Exp $";#include "HShell.h"#include "HMem.h"#include "HMath.h"#include "HWave.h"#include "HLabel.h"#include "LUtil.h"#include "LWMap.h"#include "LCMap.h"/* ------------------------ Trace Flags --------------------- */static int trace = 0;#define T_TOP   0001       /* top level tracing */#define T_CML   0002       /* class map loading *//* --------------------- Global Variables ------------------- */static ConfParam *cParm[MAXGLOBS];      /* config parameters */static int nParm = 0;static Boolean outCMapRaw = FALSE;       /* Output file in raw mode */static Boolean inCMapRaw = FALSE;        /* Read input files in raw mode */static int  unkndx  = DEF_UNKNOWNID;         /* ndx of (hdrless) unk class */static LabId unkid  = NULL;	             /* name of (hdrless) unk class */static char  unkStr[256] = DEF_UNKNOWNNAME;  /* name of (hdrless) unk class *//* --------------------- Initialisation --------------------- *//* EXPORT -> InitCMap: initialise the module */void InitCMap(void){   int i;   Boolean b;   char buf[100];   Register(lcmap_version,lcmap_vc_id);   nParm = GetConfig("LCMAP", TRUE, cParm, MAXGLOBS);   if (nParm>0){      if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i;      if (GetConfBool(cParm,nParm,"INCMAPRAW",&b)) inCMapRaw = b;       if (GetConfBool(cParm,nParm,"OUTCMAPRAW",&b)) outCMapRaw = b;       if (GetConfInt(cParm,nParm,"UNKNOWNID",&i)) unkndx = i;      if (GetConfStr(cParm,nParm,"UNKNOWNNAME",buf)) strcpy(unkStr,buf);   }   unkid = GetLabId(unkStr,TRUE);}/* --------------------- Input Routines ------------------ *//* ReadMapHeader: read header and store info in cm */static void ReadMapHeader(Source *src, ClassMap *cm, int *entries){   LMFileHdr hdr;   LMHdrKind kind;   int n;   char *s;   if (trace&T_TOP)      printf("Reading header from %s\n",src->name);   kind = ReadLMHeader(&(cm->mem), src, LCMapFilter, &hdr, &n);   if (n<0 || n > 999000)      HError(15050,"ReadMapHeader: Unlikely num map entries[%d] in %s",n,src->name);    *entries = n;   cm->entries = 0;  /* will be incremented as classes are read */   if (kind == NO_HDR) {      if (unkndx == -1 || unkid == NULL)         HError(15051,"ReadMapHeader: UNKxxx configs must be set for hdrless map");      cm->hdrless = TRUE;      cm->htkEsc = !inCMapRaw; cm->lang = NULL;   } else {       cm->name = GetLMHdrStr("NAME",hdr,FALSE);      if (cm->name == NULL)         HError(15052,"ReadMapHeader: No name in %s",src->name);            cm->htkEsc = TRUE;      if ((s=GetLMHdrStr("ESCMODE",hdr,TRUE)) != NULL) {         if (strcmp(s,"HTK")==0) cm->htkEsc = TRUE; else         if (strcmp(s,"RAW")==0) cm->htkEsc = FALSE; else            HError(15053,"ReadMapHeader: Unknown escmode %s in %s",s,src->name);      }      cm->lang = GetLMHdrStr("LANGUAGE",hdr,FALSE);   }}   /* SetClassWords: add given word to specified class */static void SetClassWords(ClassEntry *ce, WordMap *wmap, int nItem, LabId *cword){   int i;   LabId id=0;   MapEntry *me;   ClassEntry *tce;   ce->size = 0;   if (ce->inClass) {      for (i=0; i<nItem; i++) {	 id = cword[i];	 me = (MapEntry *)id->aux;	 if (!me) {	    if (trace&T_TOP) {	       printf("  Adding word %-12s from class %s to map\n",		      id->name,ce->id->name);	    }	    AddWordToMap(wmap,id);	    me = (MapEntry *)id->aux;	 }	 tce = (ClassEntry *)me->class;	 if (tce)	    HError(15090,"SetClassWords: word %s already in class %s",		   id->name,ce->id->name);	 ++ce->size;	 me->class = ce;      }   } else {      for (me=wmap->me,i=0; i<wmap->used; i++,me++) 	 me->aux.auxint = 0;      for (i=0; i<nItem; i++) {	 id = cword[i];	 me = (MapEntry *)id->aux;         if((void*)ce == (void*)me){            HError(15058, "SetClassWords: word %s cannot be in the list of words excluded from class %s",                   id->name, ce->id->name);         }	 if (!me) {	    if (trace&T_TOP) {	       printf("  Adding word %-12s from class %s to map\n",		      id->name,ce->id->name);	    }	    AddWordToMap(wmap,id); me = (MapEntry *)id->aux;	 }	 me->aux.auxint = 1;      }      for (me=wmap->me,i=0; i<wmap->used; i++,me++) {	 if (me->aux.auxint == 0) {	    tce = (ClassEntry *) me->class;	    if (tce)	       HError(15090,"SetClassWords: word %s already in class %s",		      id->name,ce->id->name);	    me->class = ce;	    ce->size++;	 } else {	    me->aux.auxint=0;	 }      }   }}/* LoadClass: load and store a single class from src */static void LoadClass(ClassMap *cm, Source *src, LabId clname, int clndx,                  int clsize, Boolean inClass){   int i,nItem;   LabId *cword;   ClassEntry *ce;   char buf[MAXSTRLEN];   if (trace&T_CML)       printf("  loading class %s[%d] from %s\n",clname->name,clsize,src->name);   ce = MakeNewClass(cm,clname,clndx,inClass);   nItem = 0;   cword = (LabId *) New(&gstack,clsize*sizeof(LabId));   for (i=0; i<clsize; i++) {      if (!GetSrcString(src,buf,cm->htkEsc))	 HError(15013,"LoadClass: Can't read word %d from %s",i+1,src->name);      cword[nItem++] = GetLabId(buf,TRUE);    }   SetClassWords(ce,cm->wmap,nItem,cword);   if (trace&T_CML)       printf("   class %s loaded\n",clname->name);   Dispose(&gstack,cword);}/* LoadMapData: load contents of src into classmap */static void LoadMapData(Source *src, ClassMap *cm, int entries){   char buf[MAXSTRLEN],*fn;   LabId id;   int i,ibuf[2],ndx,nents;   Boolean inClass=FALSE;   fn = src->name;   if (cm->hdrless) {      cm->name = CopyString(&cm->mem,fn);      if ((ClassEntry *)unkid->aux)         HError(-15092, "LoadMapData: %s already in map (index=%d)", unkid->name, ((ClassEntry*)unkid->aux)->ndx);      else         LoadClass(cm,src,unkid,unkndx,entries,FALSE);   } else {      for (i=0; i<entries; i++){	 if (!GetSrcString(src,buf,cm->htkEsc))	    HError(15013,"LoadMapData: Can't read class name %d from %s",i+1,fn);	 id = GetLabId(buf,TRUE);	 if (id->aux != NULL)	    HError(15054,"LoadMapData: Class name %s duplicate in %s",buf,fn); 	 if (!ReadInt(src,ibuf,2,FALSE))	    HError(15013,"LoadMapData: Can't read index for class %s in %s",buf,fn);	 ndx = ibuf[0];	 if (ndx > 0  && ndx < BASEWORDNDX) {	    if (cm->maxClndx < ndx) cm->maxClndx = ndx;	 } else	    HError(15055,"LoadMapData: Bad index %d for class %s in %s",ndx,buf,fn);         nents = ibuf[1];	 if (nents<1)	    HError(15056,"LoadMapData: Number of entries = %d for class %s in %s",nents,buf,fn);	 if (!GetSrcString(src,buf,cm->htkEsc))	    HError(15013,"LoadMapData: Can't read type for class %s in %s",id->name,fn);         if (strcmp(buf,"IN") == 0 )	    inClass = TRUE;         else if (strcmp(buf,"NOTIN") == 0 )            inClass = FALSE;         else	    HError(15057,"LoadMapData: Bad type %s for class %s in %s",buf,id->name,fn);	 if (nents>=1)	   LoadClass(cm,src,id,ndx,nents,inClass);      }   }   CloseSource(src);}/* --------------------- Output Routines ---------------------- *//* WriteMapHeader: write class header to f */static void WriteMapHeader(FILE *f, ClassMap *cm){   fprintf(f,"Name  = %s\n",cm->name);   fprintf(f,"Entries = %d\n",cm->entries);   fprintf(f,"EscMode  = %s\n",(cm->htkEsc)?"HTK":"RAW");   if (cm->lang != NULL)      fprintf(f,"Language  = %s\n",cm->lang);   fprintf(f,"\\Classes\\\n");}/* OutString: output given id in appropriate esc mode to f */static void OutString(FILE *f, Boolean htkEsc, LabId id){   if (!htkEsc || outCMapRaw)      fprintf(f, "%s", id->name);   else       WriteString(f,id->name,ESCAPE_CHAR);}/* WriteClassMap: Write given class map to file f */static void WriteClassMap(FILE *f, ClassMap *cm, Boolean debug){   ClassEntry *ce;   int i,h;   int *ndxlist,len,maxlen=0,avelen=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -