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

📄 hresults.c

📁 该压缩包为最新版htk的源代码,htk是现在比较流行的语音处理软件,请有兴趣的朋友下载使用
💻 C
📖 第 1 页 / 共 4 页
字号:
   else if ((numstars==0 && minplen!=slen) || minplen>slen)      match=FALSE;   else if (*p == '*') {      match=(SpRMatch(s+1,p,spkr,slen-1,minplen,numstars) ||             SpRMatch(s,p+1,spkr,slen,minplen,numstars-1) ||             SpRMatch(s+1,p+1,spkr,slen-1,minplen,numstars-1));   }   else if (*p == '%') {      *spkr=*s,spkr[1]=0;      match=SpRMatch(s+1,p+1,spkr+1,slen-1,minplen-1,numstars);      if (!match) *spkr=0;   }   else if (*p == *s || *p == '?')      match=SpRMatch(s+1,p+1,spkr,slen-1,minplen-1,numstars);   else      match=FALSE;      return(match);}/* SpMatch: return spkr if s matches pattern p */Boolean SpMatch(char *spkrpat, char *spkr, char *str){   int spkrlen, slen, minplen, numstars;   char *q,c;     if (spkrpat == NULL || str==NULL) return(FALSE);   slen = strlen(str);   spkrlen = minplen = numstars = 0;   q = spkrpat;   while ((c=*q++)) {      if (c == '*') ++numstars; else ++minplen;      if (c == '%') ++spkrlen;   }   if (spkrlen>=MAXSTRLEN)      HError(3390,"SpMatch: Speaker name too long %d vs %d",spkrlen,MAXSTRLEN);   spkr[0]=0;   if (SpRMatch(str,spkrpat,spkr,slen,minplen,numstars))      return(TRUE);   else {      spkr[0]=0;      return(FALSE);   }}/* GetSpeaker: use spkrMask to extract spkr name from recfn */Spkr *GetSpeaker(void){   char name[MAXSTRLEN], buf[MAXSTRLEN];   LabId id;   Spkr *s, *t;   Boolean found;   strcpy(buf,recfn);   if (trace&T_SPK)      printf("Finding speaker for %s ",buf);   found = SpMatch(spkrMask,name,buf);   if (!found){      ++spkrFails;      return NULL;   }   if (trace&T_SPK)      printf(":speaker is %s\n",name);   id = GetLabId(name,TRUE);   if (id->aux == 0) {      s=(Spkr*)New(&permHeap,sizeof(Spkr));      s->ins = s->del = s->sub = s->hit = 0;      s->nsyms = s->nphr = s->phrcor = 0;      s->name = id->name;  s->next = NULL;      id->aux = (Ptr) s;       ++numSpkrs;      if (spkrHead==NULL || strcmp(s->name,spkrHead->name)<0) {         s->next=spkrHead;         spkrHead=s;      }      else for (t=spkrHead;t!=NULL;t=t->next)          if (t->next == NULL || strcmp(s->name,t->next->name)<0) {            s->next=t->next;            t->next=s;            break;         }   }    else      s = (Spkr *) id->aux;   return s;}/* RecordFileStats: record info from current input file */Boolean RecordFileStats(CellPtr p){   Boolean error;   Spkr *s;   del += p->del;    ins += p->ins; /* update global counters */   sub += p->sub;    hits += p->hit;   nsyms += p->hit+p->del+p->sub; ++nphr;   error = !(p->del==0 && p->ins==0 && p->sub==0);   if (!error) ++phrcor;   if (spkrMask != NULL){       /* update speaker if reqd */      s = GetSpeaker();      if (s != NULL){          s->del += p->del;  s->ins += p->ins;         s->sub += p->sub;  s->hit += p->hit;         s->nsyms += p->hit+p->del+p->sub;  ++s->nphr;         if (!error) ++ s->phrcor;      }   }   return error;}/* ---------------------- Print Routines  ------------------------ */static Boolean headerPrinted = FALSE;  /* delay header as long as poss *//* to accumulate rec file names *//* PrintBar: print a bar of given char width with title if any */void PrintBar(int offset, int width, char c, char *title){   int i,k,tlen;      tlen = strlen(title);   if (tlen>0) tlen +=2;        /* allow for spaces */   k = (width - tlen)/2;   for (i=1; i<=offset; i++) putchar(' ');   for (i=1; i<=k; i++) putchar(c);   if (tlen>0) printf(" %s ",title);   for (i=k+tlen; i<=width; i++) putchar(c);   printf("\n");}/* PrintNBar: print a bar of given width and char, with given border chars */void PrintNBar(int width, char c, char left, char right){   int i;      putchar(left);   for (i=1; i<=width; i++) putchar(c);   putchar(right);   printf("\n");}/* PrintNMargin: print a margin for NIST format tables */void PrintNMargin(void){   int i;      for (i=1; i<=4; i++) putchar(' ');}/* PClip: clip string to given length  */void PClip(char * instr, char *outstr, int max){   char *p;   if (instr==NULL){      outstr[0] = '\0'; return;   }   if (strlen(instr) <= max){      strcpy(outstr,instr);      return;   }   p = instr + strlen(instr)-max;   strcpy(outstr,p);   outstr[0] = '>';}/* PrintHeader: print title information */void PrintHeader(void){   char datestr[255];   time_t clock = time(NULL);   int i;   char buf[100];   strcpy(datestr,ctime(&clock));   datestr[strlen(datestr)-1] = '\0';   if (nistFormat){      PrintNMargin(); PrintNBar(61,'-',',','.');      PrintNMargin();       printf("| HTK Results Analysis at %s",datestr);      PrintNBar(35-strlen(datestr),' ',' ','|');      PrintNMargin();       PClip(refid,buf,54);      printf("| Ref: %s",buf); PrintNBar(54-strlen(buf),' ',' ','|');      PrintNMargin();       PClip(recid[0],buf,54);      printf("| Rec: %s",buf); PrintNBar(54-strlen(buf),' ',' ','|');      for (i=1; i<recidUsed;i++){         PrintNMargin();          PClip(recid[i],buf,54);         printf("|    : %s",buf);          PrintNBar(54-strlen(buf),' ',' ','|');      }      if (fullResults){         PrintNMargin(); PrintNBar(61,'-','|','|');         PrintNMargin();          printf("|      FILE       |  Corr    Sub    Del    Ins    Err         |\n");       }   } else {      PrintBar(0,htkWidth,'=',"HTK Results Analysis");      printf("  Date: %s\n",datestr);      PClip(refid,buf,70);      printf("  Ref : %s\n",buf);      PClip(recid[0],buf,70);      printf("  Rec : %s\n",buf);      for (i=1; i<recidUsed;i++){         PClip(recid[i],buf,70);         printf("      : %s\n",buf);      }   }   headerPrinted = TRUE;}/* PrintFileStats:  output per file recognition statistics */void PrintFileStats(char *fn, int h, int d, int s, int i){   float accuracy,correct;   float psub,pdel,pins,perr;   int nc;   char buf[100];      if (!headerPrinted) {      PrintHeader();      if (!nistFormat)          PrintBar(0,htkWidth,'-',"File Results");   }   nc = h+d+s;   accuracy = 100.0 * ((float) (h-i) / (float) nc);   correct =  100.0 * ((float) h / (float) nc);   if (nistFormat){      psub = 100.0 * (float)s / (float)nc;      pdel = 100.0 * (float)d / (float)nc;      pins = 100.0 * (float)i / (float)nc;      perr = 100.0 - accuracy;      PrintNMargin(); PrintNBar(61,'-','|','|');      PClip(fn,buf,15);      PrintNMargin(); printf("| %15s |%7.2f%7.2f%7.2f%7.2f%7.2f        |\n",                             buf, correct,psub,pdel,pins,perr);   } else {      printf("%s:  %6.2f(%6.2f)  [H=%4d, D=%3d, S=%3d, I=%3d, N=%3d]\n",             fn, correct, accuracy, h,d,s,i,nc);   }}void PrintSpkrStats(void){   float accuracy,correct,phrcorrect;   float psub,pdel,pins,perr;   int nc;   Spkr *s;   char buf[32];   if (!headerPrinted) PrintHeader();   if (nistFormat){      PrintNMargin(); PrintNBar(61,'-','|','|');      PrintNMargin();       printf("|    SPKR | # Snt |  Corr    Sub    Del    Ins    Err  S. Err |\n");    }else{      PrintBar(0,htkWidth,'-',"Speaker Results");      printf("spkr: %%Corr( %%Acc )  [ Hits, Dels, Subs, Ins, #Words] %%S.Corr [ #Sent ]\n");      PrintBar(0,htkWidth,'-',"");   }   for (s=spkrHead; s!=NULL; s=s->next){      nc = s->hit + s->del + s->sub;      accuracy = 100.0 * (float) (s->hit-s->ins) / (float) s->nsyms;      correct = 100.0 * (float) s->hit / (float) s->nsyms;      phrcorrect = 100.0 * ((float) s->phrcor / (float) s->nphr);      if (nistFormat){         psub = 100.0 * (float)s->sub / (float)nc;         pdel = 100.0 * (float)s->del / (float)nc;         pins = 100.0 * (float)s->ins / (float)nc;         perr = 100.0 - accuracy;         PrintNMargin(); PrintNBar(61,'-','|','|');         PClip(s->name,buf,7);         PrintNMargin(); printf("| %7s |",buf);         printf("%5d  |%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f |\n",                s->nphr,correct,psub,pdel,pins,perr,100.0-phrcorrect);      } else {         PClip(s->name,buf,8);         printf("%s: %6.2f(%6.2f)  [H=%4d, D=%3d, S=%3d, I=%3d, N=%4d]",                buf, correct, accuracy, s->hit,s->del,s->sub,s->ins,nc);         printf(" %6.2f [N=%3d]\n",                phrcorrect,s->nphr);      }   }}/* PrintGlobalStats:  output global recognition statistics */void PrintGlobalStats(void){   float accuracy,correct,phrcorrect;   float psub,pdel,pins,perr;   void OutConMat(void);   if (!headerPrinted) PrintHeader();   accuracy = 100.0 * (float) (hits-ins) / (float) nsyms;   correct = 100.0 * (float) hits / (float) nsyms;   phrcorrect = 100.0 * ((float) phrcor / (float) nphr);   if (nistFormat){      if (spkrMask == NULL) {         PrintNMargin(); PrintNBar(61,'=','|','|');         PrintNMargin();          printf("|           # Snt |  Corr    Sub    Del    Ins    Err  S. Err |\n");          PrintNMargin(); PrintNBar(61,'-','|','|');      } else{         PrintSpkrStats();         PrintNMargin(); PrintNBar(61,'=','|','|');      }      psub = 100.0 * (float)sub / (float)nsyms;      pdel = 100.0 * (float)del / (float)nsyms;      pins = 100.0 * (float)ins / (float)nsyms;      perr = 100.0 - accuracy;      PrintNMargin(); printf("| Sum/Avg |");      printf("%5ld  |%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f |\n",             nphr,correct,psub,pdel,pins,perr,100.0-phrcorrect);      PrintNMargin(); PrintNBar(61,'-','`','\'');      if (outPStats)          OutConMat();   } else {      if (spkrMask != NULL) PrintSpkrStats();      PrintBar(0,htkWidth,'-',"Overall Results");      printf("%s: %%Correct=%.2f [H=%ld, S=%ld, N=%ld]\n",phraseStr,             phrcorrect,phrcor,nphr-phrcor,nphr);      printf("%s: %%Corr=%.2f, Acc=%.2f",phoneStr,correct,accuracy);      printf(" [H=%ld, D=%ld, S=%ld, I=%ld, N=%ld]\n",hits,del,sub,ins,nsyms);      if (outPStats)          OutConMat();      PrintBar(0,htkWidth,'=',"");   }   if (spkrFails>0)      printf("\n** Speaker Pattern '%s' Failed %d Times **\n\n",             spkrMask,spkrFails);}/* ------------------------ DP Matching ------------------------ *//* In the DP matching, the recognition output label file is    referred to as the test file, the annotated label file is   referred to as the reference file. Test labels are indexed   by i and ref labels are indexed by j.  Viewed as a grid,   the test labels span the horizantal axis and the ref labels   span the vertical.  The cell in column i and row j represents   the match between the i'th test label and the j'th ref label*/static const int subPen = 10;     /* error penalties */static const int delPen = 7;static const int insPen = 7;static const int subPenNIST = 4;  /* NIST error penalties */static const int delPenNIST = 3;static const int insPenNIST = 3;static CellPtr *grid;     /* matrix of cells */static LabId *lRef,*lTest;static int nRef,nTest;/* DumpGrid: for debugging */void DumpGrid(void){   int i,j;   printf("Grid -\n");   for (j=0; j<=nRef; j++)      if (j==0)          printf("%10s","");      else         printf("%5.4s",lRef[j]->name);   printf("\n");      for (i=0; i<=nTest; i++) {      if (0==i)          printf("%5s","");      else         printf("%5.4s",lTest[i]->name);      for (j=0; j<=nRef; j++) {         printf("%4d",grid[i][j].score);         if (grid[i][j].dir==DIAG)            printf("d");         else if (grid[i][j].dir==HOR)            printf("h");         else if (grid[i][j].dir==VERT)            printf("v");         else             printf("n");      }      printf("\n");   }   fflush(stdout);}/* CreateGrid: Create a grid of cells of the given dimensions */void CreateGrid(void){   LLink l;   LabId labid;   int i;      nRef = CountAuxLabs(ref,rlev);   nTest = CountAuxLabs(test,tlev);   grid=(CellPtr *)New(&tempHeap,(nTest+1)*sizeof(CellPtr));   for (i=0; i<=nTest;i++)      grid[i]=(CellPtr) New(&tempHeap,(nRef+1)*sizeof(Cell));   lRef = (LabId*) New(&tempHeap,sizeof(LabId)*nRef);lRef--;   lTest = (LabId*) New(&tempHeap,sizeof(LabId)*nTest);lTest--;   grid[0][0].score = grid[0][0].ins = grid[0][0].del = 0;   grid[0][0].sub = grid[0][0].hit = 0;   grid[0][0].dir = NIL;   for (i=1;i<=nTest;i++) {      l=GetAuxLabN(test,i,tlev);      labid = ((tlev==0) ? l->labid : l->auxLab[tlev]);      lTest[i]=labid;      grid[i][0] = grid[i-1][0];      grid[i][0].dir = HOR;      if (labid != nulClass) {         grid[i][0].score += nistAlign ? insPenNIST : insPen;         ++grid[i][0].ins;      }   }   for (i=1;i<=nRef;i++) {      l=GetAuxLabN(ref,i,rlev);      labid = ((rlev==0) ? l->labid : l->auxLab[rlev]);      lRef[i]=labid;      grid[0][i] = grid[0][i-1];      grid[0][i].dir = VERT;      if (labid != nulClass) {         grid[0][i].score += nistAlign ? delPenNIST : delPen;         ++grid[0][i].del;      }   }}/* FreeGrid: free storage allocated to grid and label arrays */void FreeGrid(void){   Dispose(&tempHeap,grid);

⌨️ 快捷键说明

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