int cSemaineUserinfoSender::processComponentMessage( cComponentMessage *msg ) 
{ 
  if (isMessageType(msg,"classificationResult")) {  
     if (!strcmp(msg->msgname, "gender")) { 
       sendGender(msg);
       return 1;
     } else if (!strcmp(msg->msgname, "offtalk")) {
       sendOffTalk(msg);
       return 1;
     }
  }
  else if (isMessageType(msg, "speakerId")) {  
    sendSpeakerId(msg);
    return 1;
  }
  else if (isMessageType(msg, "pitchDirection")) {  
    SMILE_IDBG(3, "received 'pitchDirection' message");
    sendPitchDirection(msg);
    return 1;  // message was processed
  }
  else if (isMessageType(msg, "turnSpeakingStatus")) {
    SMILE_IDBG(3, "received 'turnSpeakingStatus' message: %i", msg->intData[0]);
    sendSpeakingStatus(msg, msg->intData[0]);
    return 1; // message was processed
  }
  return 0; // if message was not processed
}  
int cSemaineEmmaSender::processComponentMessage( cComponentMessage *_msg ) 
{ 
  if (isMessageType(_msg,"classificationResult")) {  
    // determine origin by message's user-defined name, which can be set in the config file
    SMILE_IDBG(3,"received 'classificationResult' message");
    if (!strcmp(_msg->msgname,"arousal")) sendArousalC(_msg);
    else if (!strcmp(_msg->msgname,"valence")) sendValenceC(_msg);
    else if (!strcmp(_msg->msgname,"interest")) sendInterestC(_msg);
    else if (!strcmp(_msg->msgname,"gender")) sendGender(_msg);
    else if (!strcmp(_msg->msgname,"power")) sendPowerC(_msg);
    else if (!strcmp(_msg->msgname,"intensity")) sendIntensityC(_msg);
    else if (!strcmp(_msg->msgname,"anticipation")) sendAnticipationC(_msg);
    return 1;  // message was processed
  }
  else if (isMessageType(_msg,"pitchDirection")) {  
    SMILE_IDBG(3,"received 'pitchDirection' message");
    sendPitchDirection(_msg);
    return 1;  // message was processed
  }
  else if (isMessageType(_msg,"asrKeywordOutput")) {  
    SMILE_IDBG(3,"received 'asrKeywordOutput' message");
    sendKeywords(_msg);
    return 1;  // message was processed
  }
  else if (isMessageType(_msg,"turnSpeakingStatus")) {
    SMILE_IDBG(2,"received 'turnSpeakingStatus' message: %i",_msg->intData[0]);
    sendSpeakingStatus(_msg, _msg->intData[0]);
    return 1; // message was processed
  }

  return 0; // if message was not processed
}  
Ejemplo n.º 3
0
void cLibsvmLiveSink::fetchConfig()
{
  cDataSink::fetchConfig();
  
  modelfile = getStr("model");
  SMILE_IDBG(2,"filename of model to load = '%s'",modelfile);

  scalefile = getStr("scale");
  SMILE_IDBG(2,"filename of scale data to load = '%s'",scalefile);

  fselection = getStr("fselection");
  if (fselection != NULL) SMILE_IDBG(2,"filename of fselection to load = '%s'",fselection);

  classes = getStr("classes");
  if (classes != NULL) SMILE_IDBG(2,"filename of class mapping to load = '%s'",classes);

  lag = getInt("lag");
  if (lag != 0) SMILE_IDBG(2,"lag = %i frames",lag);

  printResult = getInt("printResult");
  SMILE_IDBG(2,"printResult = %i",printResult);

  predictProbability = getInt("predictProbability");
  SMILE_IDBG(2,"predictProbability = %i",predictProbability);

  resultRecp = getStr("resultRecp");
  SMILE_IDBG(2,"resultRecp = '%s'",resultRecp);
  if (resultRecp != NULL) sendResult = 1;

  resultMessageName = getStr("resultMessageName");
  SMILE_IDBG(2,"resultMessageName = '%s'",resultMessageName);
}
Ejemplo n.º 4
0
int cLibsvmLiveSink::buildEnabledSelFromNames(long N, const FrameMetaInfo *fmeta)
{
  int n,i;
  SMILE_IDBG(3,"computing mapping from feature names to feature indicies");
  outputSelIdx.nFull = N;
  outputSelIdx.nSel = outputSelStr.n;
  outputSelIdx.enabled = (long *)calloc(1,sizeof(long)*outputSelIdx.nFull);
  for (n=0; n<N; n++) {
    for (i=0; i<outputSelStr.n; i++) {
      if (!strcmp(fmeta->getName(n,NULL),outputSelStr.names[i]))
        outputSelIdx.enabled[n] = 1;
    }
  }
  SMILE_IDBG(3,"mapping computed successfully");
  return 1;
}
void cTumkwsjSink::cbResultPass1Current(Recog *recog, void *dummy)
{
  //int i, j, bgn;
  //int len, 
  int num;
  WORD_INFO *winfo;
  WORD_ID *seq;
  RecogProcess *r;
  Sentence *s;
  r=recog->process_list;
  if (! r->live) return;
  if (! r->have_interim) return;

  winfo = r->lm->winfo;
  seq = r->result.pass1.word;
  num = r->result.pass1.word_num;
  s = &(r->result.pass1);
  if ((num>0)&&(!isAbort())) {
    //juAlignPass1Keywords(r, r->am->mfcc->param);

    //create smile message:
    Kresult k;
    fillKresult(&k, seq, num, winfo, s->confidence, r->result.num_frame, /*s->align*/ NULL);
    if (resultRecp != NULL) {
      cComponentMessage msg("asrKeywordOutput");
      msg.custData = &k;
      msg.userTime1 = turnStartSmileTimeCur;
      msg.userTime2 = turnStartSmileTimeCur + ((double)(k.turnDuration))*period;
      sendComponentMessage( resultRecp, &msg );
      SMILE_IDBG(3,"sending 'asrKeywordOutput' message to '%s'",resultRecp);
    }
   //output content of k:
    int kc = 0;
    printf("----------current hypothesis:------------\n");
    printf("numOfKw:%i\n",k.numOfKw);
    printf("turnDuration:%i\n",k.turnDuration);
    printf("keywords: ");
    for (kc=0;kc<(k.numOfKw);kc++) {
      printf("%s ",k.keyword[kc]);
    }
    printf("\n");
    printf("kwConf: ");
    for (kc=0;kc<(k.numOfKw);kc++) {
      printf("%5.3f ",k.kwConf[kc]);
    }
    printf("\n");
    printf("kwStartTimes: ");
    for (kc=0;kc<(k.numOfKw);kc++) {
      printf("%.3f ",k.kwStartTime[kc]);
    }
    printf("\n");
    printf("-----------------------------------------\n");

    printf("\n\n");
    fflush(stdout);

  }
}
void cTumkwsjSink::fetchConfig()
{
  cDataSink::fetchConfig();

  configfile = getStr("configfile");
  SMILE_IDBG(2,"ASR configfile to load = '%s'",configfile);

  logfile = getStr("logfile");
  SMILE_IDBG(2,"Julius logfile = '%s'",logfile);

  glogprob = (FLOAT_DMEM)getDouble("gprob");
  klogprob = (FLOAT_DMEM)getDouble("kprob");
  numphon = getInt("numphon");

  resultRecp = getStr("resultRecp");
  SMILE_IDBG(2,"resultRecp = '%s'",resultRecp);
  if (resultRecp != NULL) sendResult = 1;

  printResult = getInt("printResult");
  SMILE_IDBG(2,"printResult = %i",printResult);

  wlenWeight = (FLOAT_DMEM)getDouble("wlenWeight");
  SMILE_IDBG(2,"wlenWeight = %f",wlenWeight);

  dynamicLm = getInt("dynamicLm");
  SMILE_IDBG(2,"dynamicLm = %i",dynamicLm);

  lmpenalty = getDouble("lmpenalty");
  SMILE_IDBG(2,"lmpenalty = %i",lmpenalty);
}
Ejemplo n.º 7
0
void cCsvSink::fetchConfig()
{
  cDataSink::fetchConfig();
  
  filename = getStr("filename");
  SMILE_IDBG(3,"filename = '%s'",filename);

  delimChar = getChar("delimChar");
  SMILE_IDBG(3,"delim = '%c'",delimChar);

  lag = getInt("lag");
  SMILE_IDBG(3,"lag = %i",lag);

  append = getInt("append");
  if (append) { SMILE_IDBG(3,"append to file is enabled"); }

  printHeader = getInt("printHeader");
  if (printHeader) { SMILE_IDBG(3,"printing header with feature names"); }

  number = getInt("number");
  if (number) { SMILE_IDBG(3,"printing of frameIndex (number) to file is enabled"); }

  timestamp = getInt("timestamp");
  if (timestamp) { SMILE_IDBG(3,"printing timestamp attribute (index 1) enabled"); }

/*
  instanceBase = getStr("instanceBase");
  SMILE_DBG(3,"instanceBase = '%s'",instanceBase);

  instanceName = getStr("instanceName");
  SMILE_DBG(3,"instanceName = '%s'",instanceName);
*/


}
Ejemplo n.º 8
0
int cNullSink::myTick(long long t)
{
  SMILE_IDBG(4,"tick # %i, reading value vector to NULL sink",t);
  cVector *vec= reader_->getNextFrame();
  if (vec == NULL) return 0;
  else 
    // tick success
    return 1;
}
Ejemplo n.º 9
0
int cSemaineWordSender::processComponentMessage( cComponentMessage *_msg ) 
{ 
  if (isMessageType(_msg,"asrKeywordOutput")) {  
    SMILE_IDBG(3,"received 'asrKeywordOutput' message");
    sendKeywords(_msg);
    return 1;  // message was processed
  }
  
  return 0; // if message was not processed
}  
Ejemplo n.º 10
0
void cFunctionalComponent::parseTimeNormOption()
{
  if (isSet("norm")) { timeNormIsSet = 1; }

  const char*Norm = getStr("norm");
  if (Norm != NULL) {
    if (!strncmp(Norm,"tur",3)) timeNorm=TIMENORM_SEGMENT;
    else if (!strncmp(Norm,"seg",3)) timeNorm=TIMENORM_SEGMENT;
    else if (!strncmp(Norm,"sec",3)) timeNorm=TIMENORM_SECOND;
    else if (!strncmp(Norm,"fra",3)) timeNorm=TIMENORM_FRAME;
  }

  SMILE_IDBG(2,"timeNorm = %i (set= %i)\n",timeNorm,timeNormIsSet);
}
int cSemaineEmotionSender::processComponentMessage( cComponentMessage *_msg ) 
{ 
  if (isMessageType(_msg,"classificationResult")) {  
    // determine origin by message's user-defined name, which can be set in the config file
    SMILE_IDBG(3,"received 'classificationResult' message");
    if (!strcmp(_msg->msgname,"arousal")) {
      // convert to EmotionML standard range: (SEMAINE uses -1 to +1, EmotionML 0 .. 1)
      _msg->floatData[0] = (_msg->floatData[0] + 1.0)/2.0;
      sendDimensionFSRE(_msg,EmotionML::VOC_FSRE_DIMENSION_AROUSAL);
    }
    else if (!strcmp(_msg->msgname,"valence")) {
      // convert to EmotionML standard range: (SEMAINE uses -1 to +1, EmotionML 0 .. 1)
      _msg->floatData[0] = (_msg->floatData[0] + 1.0)/2.0;
      sendDimensionFSRE(_msg,EmotionML::VOC_FSRE_DIMENSION_VALENCE);
    }
    else if (!strcmp(_msg->msgname,"interest")) sendInterestC(_msg);
    //else if (!strcmp(_msg->msgname,"gender")) sendGender(_msg);
    else if (!strcmp(_msg->msgname,"power")) {
      // convert to EmotionML standard range: (SEMAINE uses -1 to +1, EmotionML 0 .. 1)
      _msg->floatData[0] = (_msg->floatData[0] + 1.0)/2.0;
      sendDimensionFSRE(_msg,EmotionML::VOC_FSRE_DIMENSION_POTENCY);
    }
    else if (!strcmp(_msg->msgname,"intensity")) {
      // convert to EmotionML standard range: (SEMAINE uses -1 to +1, EmotionML 0 .. 1)
      _msg->floatData[0] = (_msg->floatData[0] + 1.0)/2.0;
      sendDimension(_msg,EmotionML::VOC_SEMAINE_INTENSITY_DIMENSION_INTENSITY, EmotionML::VOC_SEMAINE_INTENSITY_DIMENSION_DEFINITON);
    }
    else if (!strcmp(_msg->msgname,"anticipation")) {
      // invert values and map to EmotionML range: 
      _msg->floatData[0] = (1.0 - _msg->floatData[0])/2.0;
      sendDimensionFSRE(_msg,EmotionML::VOC_FSRE_DIMENSION_UNPREDICTABILITY);
    }
    return 1;  // message was processed
  }

  if (isMessageType(_msg,"classificationResults")) {  
    sendDimensionsFSRE_I(_msg);
    //TODO:    sendDimensions(_msg,EmotionML::VOC_SEMAINE_INTENSITY_DIMENSION_INTENSITY);
  }
  
  return 0; // if message was not processed
}  
Ejemplo n.º 12
0
void cLibsvmLiveSink::processResult(long long tick, long frameIdx, double time, float res, double *probEstim, int nClasses, double dur)
{
  //ros::Rate loop_rate(10);

//  int count = 0;
//  while (ros::ok())
//  {
//// %EndTag(ROS_OK)%
//    /**
//     * This is a message object. You stuff it with data, and then publish it.
//     */
//// %Tag(FILL_MESSAGE)%
//    std_msgs::String msg;

//    std::stringstream ss;
//    ss << "hello world " << count;
//    msg.data = ss.str();
//// %EndTag(FILL_MESSAGE)%

//// %Tag(ROSCONSOLE)%
//    ROS_INFO("%s", msg.data.c_str());
//// %EndTag(ROSCONSOLE)%

//    /**
//     * The publish() function is how you send messages. The parameter
//     * is the message object. The type of this object must agree with the type
//     * given as a template parameter to the advertise<>() call, as was done
//     * in the constructor above.
//     */
//// %Tag(PUBLISH)%
//    chatter_pub.publish(msg);
//// %EndTag(PUBLISH)%

//// %Tag(SPINONCE)%
//    ros::spinOnce();
//// %EndTag(SPINONCE)%

//// %Tag(RATE_SLEEP)%
//    loop_rate.sleep();
//// %EndTag(RATE_SLEEP)%
//    ++count;
//  }

  std_msgs::String emoMsg;
  std_msgs::String affectMsg;

  if (printResult) {
    if ((nCls>0)&&(nClasses > 0)&&(classNames != NULL)) {
      if (labels!=NULL) {
        if ((int)res >= nClasses) res = (float)(nClasses-1);
        if (res < 0.0) res = 0.0;
        res = (float)labels[(int)res];
      }
      if ((int)res >= nCls) res = (float)nCls;
      if (res < 0.0) res = 0.0;
      SMILE_PRINT("\n LibSAVM  '%s' result (@ time: %f) :  ~~> %s <~~",getInstName(),time,classNames[(int)res]);
      std::string instName = getInstName();
      std::string emoName = "emodbEmotion";
      std::string affectName = "abcAffect";
      if (instName == emoName)
      {
          emoMsg.data = classNames[(int)res];
          emo_pub.publish(emoMsg);
      }
      if (instName == affectName)
      {
          affectMsg.data = classNames[(int)res];
          affect_pub.publish(affectMsg);
      }
    } else {
      SMILE_PRINT("\n LibSBVM  '%s' result (@ time: %f) :  ~~> %.2f <~~",getInstName(),time,res);
    }
    if (probEstim != NULL) {
      int i;
      for (i=0; i<nClasses; i++) {
        int idx = i;
        if (labels!=NULL) idx = labels[i];
        if ((nCls>0)&&(nClasses > 0)&&(classNames != NULL)) {
          if (idx >= nCls) idx=nCls-1;
          if (idx < 0) idx = 0;
          SMILE_PRINT("     prob. class '%s': \t %f",classNames[idx],probEstim[i]);
        } else {
          SMILE_PRINT("     prob. class %i : \t %f",idx,probEstim[i]);
        }
      }
    }
  }


  // send result as componentMessage 
  if (sendResult) {
    cComponentMessage msg("classificationResult", resultMessageName);
    if ((nCls>0)&&(nClasses > 0)&&(classNames != NULL)) {
      if (labels!=NULL) {
        if ((int)res >= nClasses) res = (float)(nClasses-1);
        if (res < 0.0) res = 0.0;
        res = (float)labels[(int)res];
      }
      if ((int)res >= nCls) res = (float)nCls;
      if (res < 0.0) res = 0.0;
      strncpy(msg.msgtext, classNames[(int)res], CMSG_textLen);
    }
    msg.floatData[0] = res;
    msg.intData[0]   = nClasses;
    msg.custData     = probEstim;
    msg.userTime1    = time;
    msg.userTime2    = time+dur;

    // TO TEST .....
    sendComponentMessage( resultRecp, &msg );
    SMILE_IDBG(3,"sending 'classificationResult' message to '%s'",resultRecp);
  }
}
Ejemplo n.º 13
0
int cLibsvmLiveSink::loadSelection( const char *selFile )
{
  if (selFile != NULL) {
    if (strlen(selFile)<1) return 0;

    FILE *f = fopen(selFile,"r");
    if (f== NULL) {
      SMILE_IERR(2,"error opening feature selection file '%s' for reading! NOT using a feature selection!",selFile);
      return 0;
    }
    
    // read first line to determine filetype:
    char line[MAX_LINE_LENGTH+1];
    long nStr=0;
    fgets( line, 5, f);
    line[3] = 0;
    if (!strcmp(line,"str")) { // string list
      fselType = 2;
      SMILE_IDBG(5,"reading string list of features");
      fscanf( f, "%u\n", &nStr);
      if (nStr < 1) { COMP_ERR("Error reading feature selection file, nFeatures < 1!"); }
      outputSelStr.n = nStr;
      Nsel=nStr;
      outputSelStr.names = (char **)calloc(1,sizeof(char *)*nStr);
      int i=0; line[0] = 0;
      while(fgets(line,MAX_LINE_LENGTH,f) != NULL) {
        if (strlen( line ) > 1) { 
          line[strlen( line ) - 1] = 0;
          outputSelStr.names[i++] = strdup(line);
        }
      }
      SMILE_IDBG(5,"enabled %i features",i);
      fclose(f);
      return 1;
    } else if (!strcmp(line,"idx")) { // index list
      fselType = 1;
      SMILE_IDBG(5,"reading index list of features");
      long idx=0; int i;
      // pass1: parse for max index
      while(fscanf(f,"%u\n",&idx) == 1)
        outputSelIdx.nFull = MAX(outputSelIdx.nFull, idx);
      SMILE_IDBG(5,"max index in selection file was found to be %i",outputSelIdx.nFull);
      outputSelIdx.nFull++;
      outputSelIdx.enabled = (long *)calloc(1,sizeof(long)*outputSelIdx.nFull);
      rewind( f );
      fgets(line, 5, f); // skip header line;
      // pass2: parse for max index
      i=0;
      while(fscanf(f,"%u\n",&idx) == 1) {
        outputSelIdx.enabled[idx] = 1; // enable feature "idx"
        i++;
      }
      outputSelIdx.nSel = i;
      Nsel = i;
      SMILE_IDBG(5,"enabled %i features",i);
      fclose(f);
      return 1;
    } else { // bogus file...
      COMP_ERR("error parsing fselection file '%s'. bogus header! expected 'str' or 'idx' at beginning. found '%s'.",selFile,line);
      fclose( f );
    }
  }
  return 0;
}
// this is called from julius decoder thread... 
int cTumkwsjSink::getFv(float *vec, int n)
{ 
  int ret=0;

  smileMutexLock(dataFlgMtx);

  if (terminated) { 
    smileMutexUnlock(dataFlgMtx);  
    recog->process_want_terminate = TRUE;
    return -1; 
  }  

  // we should wait for main thread to provide data, then set a flag that data was read..
  SMILE_IDBG(4,"yes... julius requests features from us (n=%i)!",n);

  int end=0;
  do {

    lockMessageMemory();

    turnStartSmileTimeCur = turnStartSmileTime;

    // handle pre/post silence and turn detector interface
    if (turnStart) { 
      // process old turnEnd message first...
      if ((turnEnd)&&(vIdxEnd < vIdxStart)) { 
        turnEnd = 0; isTurn = 0; ret=-3; end=1; 
        turnStartSmileTimeCur = turnStartSmileTimeLast;
        SMILE_IDBG(2,"processed turn end message!");  
      }
      turnStart = 0; 
      curVidx = vIdxStart-preSil;
      isTurn = 1;
      SMILE_IDBG(2,"received turn start message!"); 
    }
    if (turnEnd) { 
      SMILE_IDBG(4,"received turn end message!"); 
      if (curVidx >= vIdxEnd+postSil) { 
        turnEnd = 0; isTurn = 0; ret=-3; end=1; SMILE_IDBG(2,"processed turn end message!");  
        turnStartSmileTimeCur = turnStartSmileTimeLast;
      }
      // if no frames have been written...
      if (curVidx == vIdxStart) { 
        SMILE_IWRN(2,"turn (vIdx %i - vIdx %i) has 0 frames (curVidx = %i)!",vIdxStart,vIdxEnd,curVidx);
        turnEnd=0; isTurn=0;
      }
    }

    unlockMessageMemory();

    if (!isTurn) { 
      smileCondWaitWMtx( tickCond, dataFlgMtx ); // wait one smile tick for things to change
    }

    if (terminated) { 
      smileMutexUnlock(dataFlgMtx);  
      recog->process_want_terminate = TRUE;
      return -1; 
    }  

  } while ((!isTurn)&&(!end));

  //printf("turn getFv\n");

  if (isTurn) {
    int result=0;
    curVec = NULL;
    while (curVec == NULL)  {
      curVec = reader->getFrame(curVidx, -1, 0, &result);
      // TODO: check if curVidx is behind ringbuffer storage space!!
      if (result & DMRES_OORleft) {
        long tmp = reader->getMinR()+10;
        if (tmp > curVidx) {
          SMILE_IWRN(2,"ASR processing tried to get feature data behind beginning of ringbuffer, which is no more available! Skipping a few frames to catch up... (%i) : %i -> %i",tmp-curVidx, curVidx, tmp);
          curVidx = tmp;
        }
      }
      if (curVec == NULL) { 
        smileCondWaitWMtx( tickCond, dataFlgMtx );  

        if (terminated) { 
          smileMutexUnlock(dataFlgMtx);  
          recog->process_want_terminate = TRUE;
          return -1; 
        }  
      }
    }
    curVidx++;
  }

  //printf("turn: %f n=%i\n",curVec->dataF[curVec->N-1],curVec->N);
  smileMutexUnlock(dataFlgMtx);

  int i;
  if (curVec != NULL) {
    for (i=0; i<MIN( curVec->N, n ); i++) {
      vec[i] = (float)(curVec->dataF[i]);
    }
  } else {
    for (i=0; i<n; i++) {
      vec[i] = 0.0;
    }
  }

  // TODO: input segmentation (via smile ComponentMessages...??)

  return ret;
}
void cTumkwsjSink::cbResultPass2(Recog *recog, void *dummy)
{
//  int i, j;
//  int len;
  char ec[5] = {0x1b, '[', '1', 'm', 0};
  WORD_INFO *winfo;
  WORD_ID *seq;
  int seqnum;
  int n, num;
  Sentence *s;
  RecogProcess *r;
  boolean multi;
//  HMM_Logical *p;
//  SentenceAlign *align;

  if (recog->process_list->next != NULL) multi = TRUE;
  else multi = FALSE;

  if (isAbort()) return;

  r=recog->process_list;
  if (! r->live) return;
  if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);

  if (r->result.status < 0) {
    switch(r->result.status) {
    case J_RESULT_STATUS_REJECT_POWER:
      printf("<input rejected by power>\n");
      break;
    case J_RESULT_STATUS_TERMINATE:
      printf("<input teminated by request>\n");
      break;
    case J_RESULT_STATUS_ONLY_SILENCE:
      printf("<input rejected by decoder (silence input result)>\n");
      break;
    case J_RESULT_STATUS_REJECT_GMM:
      printf("<input rejected by GMM>\n");
      break;
    case J_RESULT_STATUS_REJECT_SHORT:
      printf("<input rejected by short input>\n");
      break;
    case J_RESULT_STATUS_FAIL:
      printf("<search failed>\n");
      break;
    }
    return;
  }

  winfo = r->lm->winfo;
//  num = r->result.sentnum;
//assume just one sentence:
  num = 1;
//consider just sentence with index n=0
  n = 0;
  s = &(r->result.sent[n]);
  seq = s->word;
  seqnum = s->word_num;
  if (debug2_flag) {
    printf("\n%s",ec);		/* newline & bold on */
  }
  if (verbose_flag) {
    printf("p2_phon:");
    juPutHypoPhoneme(seq, seqnum, winfo);
  }
  if (debug2_flag) {
    ec[2] = '0';
    printf("%s\n",ec);		/* bold off & newline */
  }
  if (verbose_flag) {
    if (r->lmtype == LM_DFA) {
  /* output which grammar the hypothesis belongs to on multiple grammar */
  /* determine only by the last word */
      if (multigram_get_all_num(r->lm) > 1) {
	      printf("grammar%d: %d\n", n+1, s->gram_id);
      }
    }
  }
  //create smile message:
  Kresult k;
  fillKresult(&k, seq, seqnum, winfo, s->confidence, r->result.num_frame, s->align);
  return;
  if (resultRecp != NULL) {
    cComponentMessage msg("asrKeywordOutput");
    msg.custData = &k;
    msg.userTime1 = turnStartSmileTimeCur;
    msg.userTime2 = turnStartSmileTimeCur + ((double)(k.turnDuration))*period;
    sendComponentMessage( resultRecp, &msg );
    SMILE_IDBG(3,"sending 'asrKeywordOutput' message to '%s'",resultRecp);
  }
  //output content of k:
  int kc = 0;
  printf("-------result package (pass 2):----------\n");
  printf("numOfKw:%i\n",k.numOfKw);
  printf("turnDuration:%i\n",k.turnDuration);
  printf("keywords: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%s ",k.keyword[kc]);
  }
  printf("\n");
  printf("kwConf: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%5.3f ",k.kwConf[kc]);
  }
  printf("\n");
  printf("kwStartTimes: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%.3f ",k.kwStartTime[kc]);
  }
  printf("\n");
  printf("-----------------------------------------\n");

  printf("\n\n\n");
  fflush(stdout);
}
void cTumkwsjSink::cbResultPass1(Recog *recog, void *dummy)
{
  int i,j;
  static char buf[MAX_HMMNAME_LEN];
  WORD_INFO *winfo;
  WORD_ID *seq;
  int num;
  RecogProcess *r;
  Sentence *s;
  boolean multi;
//  int len;
  boolean have_progout = TRUE;

  if (isAbort()) return;

  if (recog->process_list->next != NULL) multi = TRUE;
  else multi = FALSE;

  r=recog->process_list;
  if (! r->live) return;
  if (r->result.status < 0) return;	/* search already failed  */
  if (have_progout && r->config->successive.enabled) return; /* short pause segmentation */
  if (r->config->output.progout_flag) printf("\r");

  winfo = r->lm->winfo;
  seq = r->result.pass1.word;
  num = r->result.pass1.word_num;
  s = &(r->result.pass1);
  /* words */


  if (verbose_flag) {		/* output further info */
    /* phoneme sequence */
    printf("p1_phon:");
    for (i=0;i<num;i++) {
      for (j=0;j<winfo->wlen[seq[i]];j++) {
        center_name(winfo->wseq[seq[i]][j]->name, buf);
        printf(" %s", buf);
      }
      if (i < num-1) printf(" |");
    }
    printf("\n");
    if (debug2_flag) {
    /* logical HMMs */
      printf("pass1_best_HMMseq_logical:");
      for (i=0;i<num;i++) {
        for (j=0;j<winfo->wlen[seq[i]];j++) {
          printf(" %s", winfo->wseq[seq[i]][j]->name);
        }
        if (i < num-1) printf(" |");
      }
      printf("\n");
    }
  }

  juAlignPass1Keywords(r, r->am->mfcc->param);

  //create smile message:
  Kresult k;
  fillKresult(&k, seq, num, winfo, s->confidence, r->result.num_frame, s->align);
  if (resultRecp != NULL) {
    cComponentMessage msg("asrKeywordOutput");
    msg.custData = &k;
    msg.userTime1 = turnStartSmileTimeCur;
    msg.userTime2 = turnStartSmileTimeCur + ((double)(k.turnDuration))*period;
    sendComponentMessage( resultRecp, &msg );
    SMILE_IDBG(3,"sending 'asrKeywordOutput' message to '%s'",resultRecp);
  }
 //output content of k:
  int kc = 0;
  printf("-------result package (pass 1):----------\n");
  printf("numOfKw:%i\n",k.numOfKw);
  printf("turnDuration:%i\n",k.turnDuration);
  printf("keywords: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%s ",k.keyword[kc]);
  }
  printf("\n");
  printf("kwConf: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%5.3f ",k.kwConf[kc]);
  }
  printf("\n");
  printf("kwStartTimes: ");
  for (kc=0;kc<(k.numOfKw);kc++) {
    printf("%.3f ",k.kwStartTime[kc]);
  }
  printf("\n");
  printf("-----------------------------------------\n");

  printf("\n\n");
  fflush(stdout);


}
Ejemplo n.º 17
0
int cValbasedSelector::myTick(long long t)
{
  SMILE_IDBG(4,"tick # %i, processing value vector",t);

  // get next frame from dataMemory
  cVector *vec = reader_->getNextFrame();
  if (vec == NULL) {
    return 0;
  }

  // add offset
  int i = idx;
  if (i >= vec->N) i = vec->N-1;
  FLOAT_DMEM val = vec->dataF[i];
  
  int copy = 0;
  if ( ((invert)&&(val < threshold)) || ((!invert)&&(val > threshold)) || (allowEqual && (val==threshold)) ) {
    copy = 1;
  }
  
  if (copy) {
    // TODO: remove threshold value if removeIdx == 1
    if (removeIdx == 1) {

      if (myVec==NULL) myVec = new cVector(vec->N-1 , vec->type);
      int j,n=0;
      for(j=0; j<vec->N; j++) {
        if (j!=i) {
          myVec->dataF[n] = vec->dataF[j];
          n++;
        }
      }
      myVec->tmetaReplace(vec->tmeta);
      //myVec->tmeta->cloneFrom();
      // save to dataMemory
      writer_->setNextFrame(myVec);
      //delete myVec;

    } else {
      // save to dataMemory
      writer_->setNextFrame(vec);
    }
  } else {
    if (zerovec==1) {
      int j;
      // output a zero (or predefined value) vector
      if (removeIdx == 1) {
        if (myVec==NULL) myVec = new cVector(vec->N-1 , vec->type);
        for(j=0; j<myVec->N; j++) {
          myVec->dataF[j] = outputVal;
        }
        myVec->tmetaReplace(vec->tmeta);
        writer_->setNextFrame(myVec);
      } else {
        for(j=0; j<vec->N; j++) {
          vec->dataF[j] = outputVal;
        }
        writer_->setNextFrame(vec);
      }
    }
  }

  return 1;
}
Ejemplo n.º 18
0
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);
}