enterId=GetLabId("!ENTER",TRUE); /* All sentences should or are coerced */ exitId=GetLabId("!EXIT",TRUE); /* to start enterId and end exitId */ unknownId=GetLabId("!NULL",TRUE); /* Name for words not in list */ while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1)
/* ProcessFile: process given file. If fn=NULL then direct audio */ Boolean ProcessFile(char *fn, Network *net, int utterNum, LogDouble currGenBeam, Boolean restartable) { FILE *file; ParmBuf pbuf; BufferInfo pbinfo; NetNode *d; Lattice *lat; LArc *arc,*cur; LNode *node; Transcription *trans; MLink m; LogFloat lmlk,aclk; int s,j,tact,nFrames; LatFormat form; char *p,lfn[255],buf1[80],buf2[80],thisFN[MAXSTRLEN]; Boolean enableOutput = TRUE, isPipe; if (fn!=NULL) strcpy(thisFN,fn); else if (fn==NULL && saveAudioOut) CounterFN(roPrefix,roSuffix,++roCounter,4,thisFN); else enableOutput = FALSE; if((pbuf = OpenBuffer(&bufHeap,fn,50,dfmt,TRI_UNDEF,TRI_UNDEF))==NULL) HError(3250,"ProcessFile: Config parameters invalid"); /* Check pbuf same as hset */ GetBufferInfo(pbuf,&pbinfo); if (pbinfo.tgtPK!=hset.pkind) HError(3231,"ProcessFile: Incompatible sample kind %s vs %s", ParmKind2Str(pbinfo.tgtPK,buf1), ParmKind2Str(hset.pkind,buf2)); if (pbinfo.a != NULL && replay) AttachReplayBuf(pbinfo.a, (int) (3*(1.0E+07/pbinfo.srcSampRate))); StartRecognition(vri,net,lmScale,wordPen,prScale); SetPruningLevels(vri,maxActive,currGenBeam,wordBeam,nBeam,tmBeam); tact=0;nFrames=0; StartBuffer(pbuf); while(BufferStatus(pbuf)!=PB_CLEARED) { ReadAsBuffer(pbuf,&obs); if (trace&T_OBS) PrintObservation(nFrames,&obs,13); if (hset.hsKind==DISCRETEHS){ for (s=1; s<=hset.swidth[0]; s++){ if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s])) HError(3250,"ProcessFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn); } } ProcessObservation(vri,&obs,-1,xfInfo.inXForm); if (trace & T_FRS) { for (d=vri->genMaxNode,j=0;j<30;d=d->links[0].node,j++) if (d->type==n_word) break; if (d->type==n_word){ if (d->info.pron==NULL) p=":bound:"; else p=d->info.pron->word->wordName->name; } else p=":external:"; m=FindMacroStruct(&hset,'h',vri->genMaxNode->info.hmm); printf("Optimum @%-4d HMM: %s (%s) %d %5.3f\n", vri->frame,m->id->name,p, vri->nact,vri->genMaxTok.like/vri->frame); fflush(stdout); } nFrames++; tact+=vri->nact; } lat=CompleteRecognition(vri,pbinfo.tgtSampRate/10000000.0,&ansHeap); if (lat==NULL) { if ((trace & T_TOP) && fn != NULL){ if (restartable) printf("No tokens survived to final node of network at beam %.1f\n", currGenBeam); else printf("No tokens survived to final node of network\n"); fflush(stdout); } else if (fn==NULL){ printf("Sorry [%d frames]?\n",nFrames);fflush(stdout); } if (pbinfo.a != NULL && replay) ReplayAudio(pbinfo); CloseBuffer(pbuf); return FALSE; } if (vri->noTokenSurvived && restartable) return FALSE; if (vri->noTokenSurvived && trace & T_TOP) { printf("No tokens survived to final node of network\n"); printf(" Output most likely partial hypothesis within network\n"); fflush(stdout); } lat->utterance=thisFN; lat->net=wdNetFn; lat->vocab=dictFn; if (trace & T_TOP || fn==NULL) { node=NULL; for (j=0;j<lat->nn;j++) { node=lat->lnodes+j; if (node->pred==NULL) break; node=NULL; } aclk=lmlk=0.0; while(node!=NULL) { for (arc=NULL,cur=node->foll;cur!=NULL;cur=cur->farc) arc=cur; if (arc==NULL) break; if (arc->end->word!=NULL) printf("%s ",arc->end->word->wordName->name); aclk+=arc->aclike+arc->prlike*lat->prscale; lmlk+=arc->lmlike*lat->lmscale+lat->wdpenalty; node=arc->end; } printf(" == [%d frames] %.4f [Ac=%.1f LM=%.1f] (Act=%.1f)\n",nFrames, (aclk+lmlk)/nFrames, aclk,lmlk,(float)tact/nFrames); fflush(stdout); } if (pbinfo.a != NULL && replay) ReplayAudio(pbinfo); /* accumulate stats for online unsupervised adaptation only if a token survived */ if ((lat != NULL) && (!vri->noTokenSurvived) && ((update > 0) || (xfInfo.useOutXForm))) DoOnlineAdaptation(lat, pbuf, nFrames); if (enableOutput){ if (nToks>1 && latExt!=NULL) { MakeFN(thisFN,labDir,latExt,lfn); if ((file=FOpen(lfn,NetOFilter,&isPipe))==NULL) HError(3211,"ProcessFile: Could not open file %s for lattice output",lfn); if (latForm==NULL) form=HLAT_DEFAULT; else { for (p=latForm,form=0;*p!=0;p++) { switch (*p) { case 'A': form|=HLAT_ALABS; break; case 'B': form|=HLAT_LBIN; break; case 't': form|=HLAT_TIMES; break; case 'v': form|=HLAT_PRON; break; case 'a': form|=HLAT_ACLIKE; break; case 'l': form|=HLAT_LMLIKE; break; case 'd': form|=HLAT_ALIGN; break; case 'm': form|=HLAT_ALDUR; break; case 'n': form|=HLAT_ALLIKE; break; case 'r': form|=HLAT_PRLIKE; break; } } } if(WriteLattice(lat,file,form)<SUCCESS) HError(3214,"ProcessFile: WriteLattice failed"); FClose(file,isPipe); } /* only output 1-best transcription if generating lattices */ if (nTrans > 1 && latExt != NULL) trans=TranscriptionFromLattice(&ansHeap,lat,1); /* output N-best transcriptions as usual */ else trans=TranscriptionFromLattice(&ansHeap,lat,nTrans); if (labForm!=NULL) FormatTranscription(trans,pbinfo.tgtSampRate,states,models, strchr(labForm,'X')!=NULL, strchr(labForm,'N')!=NULL,strchr(labForm,'S')!=NULL, strchr(labForm,'C')!=NULL,strchr(labForm,'T')!=NULL, strchr(labForm,'W')!=NULL,strchr(labForm,'M')!=NULL); MakeFN(thisFN,labDir,labExt,lfn); /* if(LSave(lfn,trans,ofmt)<SUCCESS) HError(3214,"ProcessFile: Cannot save file %s", lfn); */ LSave(lfn,trans,ofmt); Dispose(&ansHeap,trans); } Dispose(&ansHeap,lat); CloseBuffer(pbuf); if (trace & T_MMU){ printf("Memory State after utter %d\n",utterNum); PrintAllHeapStats(); } return !vri->noTokenSurvived; }
// # Description // X方向の小さいモデルで転位を作ってX方向を拡張するためのプログラム // # Arguments // 1. ARGV[1] // cmdsファイル // # Contents of cmds // 1. コンディションファイル // 2. 作成するモデル数 // 3. 拡張したいモデルの名前 拡張したいモデルの角度 拡張後のX方向大きさ SPBC_DZ // 4. 拡張したいモデルの名前 拡張したいモデルの角度 拡張後のX方向大きさ SPBC_DZ // 5. : // 6. : // 7. : int main (int argc, char *argv[]) { LATTICE_t lattice; MD_t md, cliped_md; CONDITION_t condition; lattice.x = NULL; md.atom = NULL; int i, j, n, nx, ny, nz; char output_file_name[256], cnd_file_name[256], cmd_name[256], mdl_name[256], cmds_update_output[256], cnd_file_input[256]; double b, b_x, b_z, new_x, scale_top_x, scale_bottom_x, rad, spbc_dz; FILE *fp, *mdl_fp, *cmds_update_fp; char *home = getenv("HOME"); char file_name[256]; if(argc > 1) { sprintf (file_name, "%s", argv[1]); } else { fprintf (stdout, "ファイル名: "); fflush (stdout); fscanf (stdin, "%s", file_name); } sprintf (cmd_name, "%s/lab_src/cmds/%s.cmds", home, file_name); fp = fopen (cmd_name, "r"); if (fp == NULL) { fprintf (stdout, "%s ファイルが開けません\n", file_name); return 1; } sprintf (mdl_name, "%s/lab_src/mdls/%s.mdls", home, file_name); mdl_fp = fopen (mdl_name, "w"); sprintf (cmds_update_output, "%s/lab_src/cmds/%s_update.cmds", home, file_name); cmds_update_fp = fopen (cmds_update_output, "w"); fscanf (fp, "%s", cnd_file_name); fscanf (fp, "%d", &n); // fscanf (fp, "%lf %lf %lf", &lx, &ly, &lz); ARG_t arg[n]; sprintf (cnd_file_input, "%s/lab_src/%s", home, cnd_file_name); fprintf(cmds_update_fp, "%s\n", cnd_file_name); fprintf(cmds_update_fp, "%d\n", n); for (i = 0; i < n; i++) { fscanf (fp, "%lf%lf%lf%lf%lf%lf", &arg[i].a0, &arg[i].deg, &arg[i].clip_x, &arg[i].lx, &arg[i].ly, &arg[i].lz); } for (i = 0; i < n; i++) { InitializeAtoms (&md); InitializeAtoms (&cliped_md); InitializeLattice (&lattice); sprintf (output_file_name, "%s/lab_src/lats/bcc110_deg%.4lf.lat", home, arg[i].deg); rad = (arg[i].deg - 90.0) * M_PI / 180.0; if (ReadLattice (&lattice, output_file_name)) { GenerateLatticeType0 (&lattice, arg[i].a0); GenerateAtoms (&md, &lattice, 200, 1, 200); for (j = 0; j < md.nAtoms; j++) { md.atom[j].x -= md.lx / 2.0; md.atom[j].y -= md.ly / 2.0; md.atom[j].z -= md.lz / 2.0; } ClipAtoms (&md, &cliped_md, arg[i].clip_x, arg[i].a0 / 4.0, rad, arg[i].a0); WriteLattice (&cliped_md, output_file_name); ReadLattice (&lattice, output_file_name); } nx = ceil (arg[i].lx / lattice.lx); ny = ceil (arg[i].ly / (2.0 * lattice.ly)) * 2; // 偶数 nz = ceil (arg[i].lz / lattice.lz); GenerateAtoms (&md, &lattice, nx, ny, nz); // CheckAtomsInDiscRange (&md, md.lx / 2.0, md.ly / 2.0 + arg[i].a0 / 4.0, 0.0, 0.0, 0.0, 1.0, 11.2, md.lz * 10.0); // SetAtomType (&md, 1); // UncheckAllAtoms (&md); b = arg[i].a0 * sqrt (3) / 2.0; b_x = b * cos (rad); b_z = b * sin (rad); new_x = md.lx + b_x / 2.0; // new_x = md.lx; // 下に合わせる // new_x = md.lx + b_x; // 上に合わせる scale_top_x = new_x / (md.lx + b_x); scale_bottom_x = new_x / md.lx; spbc_dz = b_z / 2.0; // cutting from right bottom // CheckAtomsInCubeRange (&md, md.lx - b_x, md.lx, 0.0, md.ly / 2.0 - arg[i].a0 / 4.0, 0.0, md.lz); // cutting from left top CheckAtomsInCubeRange (&md, -INF, 2.0 * b_x, md.ly / 2.0 - arg[i].a0 / 4.0, INF, -INF, INF); DuplicateAtoms (&md, md.lx, 0.0, 0.0); // SetAtomType (&md, 1); UncheckAllAtoms (&md); CheckAtomsInYRange (&md, -INF, md.ly / 2.0 - arg[i].a0 / 4.0); Scale (&md, scale_bottom_x, 1.0, 1.0, scale_bottom_x, 1.0, 1.0); Deform (&md, md.lx, spbc_dz); UncheckAllAtoms (&md); CheckAtomsInYRange (&md, md.ly / 2.0 - arg[i].a0 / 4.0, INF); Scale (&md, scale_top_x, 1.0, 1.0, 1.0, 1.0, 1.0); Deform (&md, md.lx, -spbc_dz); UncheckAllAtoms (&md); // Displacement (&md, md.lx / 2.0, md.ly / 2.0 + arg[i].a0 / 4.0, b_x, b_z); CheckAtomsInYRange (&md, -INF, 10.6); CheckAtomsInYRange (&md, md.ly - 10.6, INF); SetFixAtomBC (&md, 2); UncheckAllAtoms (&md); CheckAtomsInXRange (&md, -INF, 2.0 * b_x); CheckAtomsInXRange (&md, md.lx - 2.0 * b_x, INF); ValidateDuplication (&md, spbc_dz, arg[i].a0 / 4.0); UncheckAllAtoms (&md); // sprintf (output_file_name, "deg_%lf.xxyz", arg[i].deg); // WriteAtomsToXXYZ (&md, output_file_name); ReadCondition (&condition, cnd_file_input); condition.bc.displacement_ux = cos(rad); condition.bc.displacement_uz = sin(rad); condition.bc.displacement_h = 10.6; condition.bc.stress_ex = cos(rad); condition.bc.stress_ez = sin(rad); condition.bc.spbc_dz = spbc_dz; sprintf (output_file_name, "%s_deg%.4lf_nx%d_ny%d_nz%d_mix", file_name, arg[i].deg, nx, ny, nz); fprintf(cmds_update_fp, "%s %lf %lf\n", output_file_name, arg[i].deg, spbc_dz); strcat (output_file_name, ".mdl"); WriteAtomsToMDL (&md, output_file_name, condition); fprintf(mdl_fp, "%s\n", output_file_name); } fclose (fp); fclose (mdl_fp); fclose (cmds_update_fp); return 0; }