void cFunctionalModulation::fetchConfig() { ignoreLastFrameIfTooShort_ = getInt("ignoreLastFrameIfTooShort"); removeNonZeroMean_ = getInt("removeNonZeroMean"); stftWinSizeSec_ = getDouble("stftWinSizeSec"); stftWinStepSec_ = getDouble("stftWinStepSec"); if (stftWinStepSec_ == 0.0) { stftWinStepSec_ = stftWinSizeSec_; } if (isSet("stftWinSizeFrames")) { stftWinSizeFrames_ = getInt("stftWinSizeFrames"); stftWinSizeSec_ = 0.0; } if (isSet("stftWinStepFrames")) { stftWinStepFrames_ = getInt("stftWinStepFrames"); stftWinStepSec_ = 0.0; } if (stftWinStepFrames_ == 0) { stftWinStepFrames_ = stftWinSizeFrames_; } modSpecMinFreq_ = getDouble("modSpecMinFreq"); modSpecMaxFreq_ = getDouble("modSpecMaxFreq"); if (isSet("modSpecNumBins")) { modSpecNumBins_ = getInt("modSpecNumBins"); modSpecResolution_ = (modSpecMaxFreq_ - modSpecMinFreq_) / (double)(modSpecNumBins_ - 1); } else { modSpecResolution_ = getDouble("modSpecResolution"); modSpecNumBins_ = (int)round((modSpecMaxFreq_ - modSpecMinFreq_) / modSpecResolution_) + 1; } SMILE_IMSG(2, "modSpecNumBins_ = %i", modSpecNumBins_); if (getInt("showModSpecScale")) { for (int i = 0; i < modSpecNumBins_; i++) { SMILE_IMSG(1, "modulation spectrum bin %i : %f Hz", i, modSpecMinFreq_ + (double)i * modSpecResolution_); } } const char * wf = getStr("fftWinFunc"); if (wf != NULL) { winFuncId_ = winFuncToInt(wf); } enab[0] = 1; cFunctionalComponent::fetchConfig(); nEnab += modSpecNumBins_ - 1; // -1 because enab[0] = 1 will increase nEnab by 1 }
/* parse a line of the format: word <tab> logprob_weight add the logprob to the lmWeights array at the correct position */ int cTumkwsjSink::parseLmWeightsLine(char *line, long lineNr, const char *lmfile) { int ret = 0; if (line != NULL) { char *l=line; long le = (long)strlen(line); while((le>0)&&((l[le-1]=='\n')||(l[le-1]=='\r'))) { l[le-1] = 0; le--; } char *cf = strchr(l,'\t'); if (cf == NULL) cf = strchr(l,' '); if (cf != NULL) { *cf=0; cf++; le=(long)strlen(cf); while ((le>0)&&(cf[0]=='\t')||(cf[0]==' ')) {cf++; le--;} while ((le>0)&&(cf[le-1]=='\t')||(cf[le-1]==' ')) {cf[le-1]=0; le--;} double lmW=0.0; char *ep=NULL; if (le > 0) lmW = strtod(cf,&ep); le=(long)strlen(l); while ((le>0)&&(l[0]=='\t')||(l[0]==' ')) {l++; le--;} while ((le>0)&&(l[le-1]=='\t')||(l[le-1]==' ')) {l[le-1]=0; le--;} if (ep == cf) { SMILE_IERR(1,"parse error on line %i of lmweights file '%s', expected a number after the <tab> cf='%s'",lineNr,lmfile,cf); lmW = 0.0; } if (le>0) { int i; for (i=0; i<numWords; i++) { //printf("XXX %s -",lmWinfo->woutput[i]); if (strcasecmp(lmWinfo->woutput[i],l) == 0) { SMILE_IMSG(3,"adding lmweight %f for word '%s'",lmW,l); lmWeights[i] = (LOGPROB)lmW; ret = 1; break; } } } } } return ret; }
int cTumkwsjSink::setupJulius() { try { int argc=3; char* argv[3] = {"julius","-C",NULL}; if (configfile != NULL) argv[2]=strdup(configfile); else argv[2]=strdup("kws.cfg"); /* add application option dummies */ /* j_add_option("-gprob", 1, 1, "garbage probability", opt_gprob); j_add_option("-kprob", 1, 1, "keyword probability", opt_kprob); j_add_option("-knum", 1, 1, "number of keywords", opt_knum); */ /* create a configuration variables container */ jconf = j_jconf_new(); // j_config_load_file(jconf, strdup(configfile)); if (j_config_load_args(jconf, argc, argv) == -1) { COMP_ERR("error parsing julius decoder options, this might be a bug. see tumkwsjSink.cpp!"); j_jconf_free(jconf); free(argv[2]); return 0; } free(argv[2]); /* output system log to a file */ if (getInt("debug") != 1) { jlog_set_output(NULL); } /* here you can set/modify any parameter in the jconf before setup */ jconf->input.type = INPUT_VECTOR; jconf->input.speech_input = SP_EXTERN; jconf->decodeopt.realtime_flag = TRUE; // ??? jconf->ext.period = (float)(reader->getLevelT()); jconf->ext.veclen = reader->getLevelN(); jconf->ext.userptr = (void *)this; jconf->ext.fv_read = external_fv_read_loader; /* Fixate jconf parameters: it checks whether the jconf parameters are suitable for recognition or not, and set some internal parameters according to the values for recognition. Modifying a value in jconf after this function may be errorous. */ if (j_jconf_finalize(jconf) == FALSE) { SMILE_IERR(1,"error finalising julius jconf in setupJulius()!"); j_jconf_free(jconf); return 0; } /* create a recognition instance */ recog = j_recog_new(); /* use user-definable data hook to set a pointer to our class instance */ recog->hook = (void *)this; /* assign configuration to the instance */ recog->jconf = jconf; /* load all files according to the configurations */ if (j_load_all(recog, jconf) == FALSE) { SMILE_IERR(1, "Error in loading model for Julius decoder"); j_recog_free(recog); return 0; } SMILE_IMSG(2,"garbage prob.: %f",glogprob); SMILE_IMSG(2,"keyword prob.: %f",klogprob); SMILE_IMSG(2,"number of phonemes: %i",numphon); // register user LM, get vocab size, and init lmWeights with zero or load from file PROCESS_LM *lm; for(lm=recog->lmlist;lm;lm=lm->next) { if (lm->lmtype == LM_PROB) { lm->winfo->userptr = (void*)this; // PATCH: sent/vocabulary.h (WORD_INFO struct): ++ void * userptr; // Pointer to userdata.... j_regist_user_lm_func(lm, userlm_uni_loader, userlm_bi_loader, userlm_lm_loader); if ((numWords==0)&&((long)(lm->winfo->num)>0)) { lmWinfo = lm->winfo; numWords = (long)(lm->winfo->num); } } } // load lmWeights data: //printf("XXX HEREA"); if (dynamicLm) { //printf("XXX HERE0"); if (lmWinfo != NULL) { //printf("XXX HERE"); lmWeights = (LOGPROB*)malloc(sizeof(LOGPROB)*numWords); if (lmWeights == NULL) { OUT_OF_MEMORY; } int i; for (i=0; i<numWords; i++) { lmWeights[i] = (LOGPROB)lmpenalty; } const char *lmfile = getStr("lmfile"); if (lmfile != NULL) { FILE *lf=fopen(lmfile,"r"); if (lf == NULL) { SMILE_IERR(1,"Error opening word weights file (lmfile) '%s'",lmfile); } else { SMILE_IMSG(1,"lmfile: '%s'",lmfile); long lineNr = 0; char *line=NULL; size_t len=0; size_t r=-1; do { r = getline(&line, &len, lf); //printf("XXX LINE '%s'",line); if ((r != (size_t)-1)&&(line!=NULL)) { lineNr++; parseLmWeightsLine(line,lineNr,lmfile); } } while (r != (size_t)-1); } } } else { SMILE_IERR(1,"no language model word info (vocabulary) found, check julius config!"); } } //---- /* checkout for recognition: build lexicon tree, allocate cache */ if (j_final_fusion(recog) == FALSE) { fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); j_recog_free(recog); if (logfile) fclose(fp); return 0; } setupCallbacks(recog, NULL); /* output system information to log */ j_recog_info(recog); terminated = FALSE; } catch (int) { } juliusIsSetup=1; return 1; }
int cArffSink::myFinaliseInstance() { int ap=0; if (disabledSink_) { filehandle = NULL; return 1; } int ret = cDataSink::myFinaliseInstance(); if (ret==0) return 0; if (append) { // check if file exists: filehandle = fopen(filename, "r"); if (filehandle != NULL) { fclose(filehandle); filehandle = fopen(filename, "a"); ap=1; } else { filehandle = fopen(filename, "w"); } } else { filehandle = fopen(filename, "w"); } if (filehandle == NULL) { COMP_ERR("Error opening file '%s' for writing (component instance '%s', type '%s')",filename, getInstName(), getTypeName()); } if (instanceNameFromMetadata) { prname = 1; } else { if ((instanceBase!=NULL)&&(strlen(instanceBase)>0)&& (instanceBase[0] != '-' || strlen(instanceBase) > 1) ) prname = 2; if ((instanceName!=NULL)&&(strlen(instanceName)>0)&& (instanceName[0] != '-' || strlen(instanceName) > 1) ) prname = 1; } long _N = reader_->getLevelN(); if (!ap) { // write arff header .... fprintf(filehandle, "@relation %s%s%s",relation,NEWLINE,NEWLINE); if (prname) { fprintf(filehandle, "@attribute name string%s",NEWLINE); } if (number) { fprintf(filehandle, "@attribute frameIndex numeric%s",NEWLINE); } if (timestamp) { fprintf(filehandle, "@attribute frameTime numeric%s",NEWLINE); } if (frameLength) { fprintf(filehandle, "@attribute frameLength numeric%s",NEWLINE); } long i; if (_N > 10000) { SMILE_IMSG(2,"writing ARFF header (%i features), this may take a while (it is a lot of data and heavy weight string formatting) ...",_N); } else { SMILE_IMSG(2,"writing ARFF header (%i features)...",_N); } for(i=0; i<_N; i++) { char *tmp = reader_->getElementName(i); fprintf(filehandle, "@attribute %s numeric%s",tmp,NEWLINE); free(tmp); if ((i>0)&&(i%20000==0)) { SMILE_IMSG(2,"Status: %i feature names written.",i); } } if (_N > 6000) { SMILE_IMSG(2,"finished writing ARFF header."); } // TODO: classes..... as config file options... if (nClasses > 0) { for (i=0; i<nClasses; i++) { if (classtype[i] == NULL) fprintf(filehandle, "@attribute %s numeric%s",classname[i],NEWLINE); else fprintf(filehandle, "@attribute %s %s%s",classname[i],classtype[i],NEWLINE); } } else { // default dummy class attribute... if (printDefaultClassDummyAttribute) { fprintf(filehandle, "@attribute class {0,1,2,3}%s",NEWLINE); } } fprintf(filehandle, "%s@data%s%s",NEWLINE,NEWLINE,NEWLINE); fflush(filehandle); } return ret; }
void cArffSink::fetchConfig() { cDataSink::fetchConfig(); filename = getStr("filename"); if (filename == NULL || *filename == 0 || (*filename == '?' && *(filename+1) == 0)) { SMILE_IMSG(2, "No filename given, disabling this sink component."); disabledSink_ = true; errorOnNoOutput_ = 0; } lag = getInt("lag"); SMILE_IDBG(3,"lag = %i",lag); append = getInt("append"); if (append) { SMILE_IDBG(3,"append to file is enabled"); } printDefaultClassDummyAttribute = getInt("printDefaultClassDummyAttribute"); if (isSet("frameTime")) timestamp = getInt("frameTime"); else timestamp = getInt("timestamp"); if (timestamp) { SMILE_IDBG(3,"printing timestamp attribute enabled"); } if (isSet("frameIndex")) number = getInt("frameIndex"); else number = getInt("number"); if (number) { SMILE_IDBG(3,"printing instance number (=frame number) attribute enabled"); } frameLength = getInt("frameLength"); relation = getStr("relation"); SMILE_IDBG(3,"ARFF relation = '%s'",relation); instanceBase = getStr("instanceBase"); SMILE_IDBG(3,"instanceBase = '%s'",instanceBase); instanceName = getStr("instanceName"); SMILE_IDBG(3,"instanceName = '%s'",instanceName); int i; nClasses = getArraySize("class"); //printf("nclasses: %i\n", nClasses); classname = (char**)calloc(1,sizeof(char*)*nClasses); classtype = (char**)calloc(1,sizeof(char*)*nClasses); for (i=0; i<nClasses; i++) { const char *tmp = getStr_f(myvprint("class[%i].name",i)); if (tmp!=NULL) classname[i] = strdup(tmp); tmp = getStr_f(myvprint("class[%i].type",i)); if (tmp!=NULL) classtype[i] = strdup(tmp); } /* ConfigType * classType = new ConfigType("arffClass"); classType->setField("name", "name of target", "class"); classType->setField("type", "numeric, or nominal (= list of classes)", "numeric"); ct->setField("class","definition of class target attributes (array for multiple targets/classes)", classType, ARRAY_TYPE); ConfigType * targetType = new ConfigType("arffTarget"); targetType->setField("instance", "array containing targets for each instance", 0,ARRAY_TYPE); targetType->setField("all", "one common target for all processed instances", 0); */ if (getArraySize("target") != nClasses) { SMILE_ERR(1,"number of targets (%i) is != number of class attributes (%i)!",getArraySize("target"),nClasses); } else { targetall = (char**)calloc(1,sizeof(char*)*nClasses); targetinst = (char***)calloc(1,sizeof(char**)*nClasses); nInst = -2; for (i=0; i<nClasses; i++) { char *tmp = myvprint("target[%i].instance",i); const char *t = getStr_f(myvprint("target[%i].all",i)); if (t!=NULL) targetall[i] = strdup(t); long ni = getArraySize(tmp); if (nInst==-2) nInst = ni; // -1 if no array else { if (nInst != ni) COMP_ERR("number of instances in target[].instance array is not constant among all targets! %i <> %i",nInst,ni); } int j; if (nInst > 0) { targetinst[i] = (char**)calloc(1,sizeof(char*)*nInst); for (j=0; j<nInst; j++) { t = getStr_f(myvprint("%s[%i]",tmp,j)); if (t!=NULL) targetinst[i][j] = strdup(t); } } free(tmp); } } instanceNameFromMetadata = getInt("instanceNameFromMetadata"); SMILE_IDBG(2,"instanceNameFromMetadata = %i",instanceNameFromMetadata); useTargetsFromMetadata = getInt("useTargetsFromMetadata"); SMILE_IDBG(2,"useTargetsFromMetadata = %i",useTargetsFromMetadata); frameTimeAdd= getDouble("frameTimeAdd"); // ct->setField("target","targets (classes) for each target (class) attribute",targetType,ARRAY_TYPE); }