speech/speech-to-text/stt.c
int stt_listen(char *buffer) {
  int found;
  int bytesread;
  found = 0;
  while ((bytesread = read(lisfd[0], interim, 127)) > 0) {
    int i;
    interim[bytesread] = '\0';
    if (bufindex + bytesread >= sizeof(readbuf)) {
      memmove(readbuf, &readbuf[128], 128);
    }
    // state machine
    for (i = 0; i < bytesread; i++) {
      if (interim[i] == '\n') {
        if (strncmp(readbuf, "hypothesis:", 11) == 0) {
          bufindex -= 13;
          strncpy(phrase, &readbuf[12], bufindex);
          phrase[bufindex] = '\0';
          found = 1;
        }
        bufindex = 0;
      } else {
        readbuf[bufindex] = interim[i];
        if (interim[i] != '\0') {
          bufindex++;
        }
      }
      readbuf[bufindex] = '\0';
    }
  }
  if (found) {
    strcpy(buffer, phrase);
    return strlen(phrase);
  } else {
    return 0;
  }
}
/** Gets the current state of signals for the sigframe
 *  @param buffer
 *    the buffer to copy the hypothesis to
 *  @return the length of the buffer
 */
Gets the current state of signals for the sigframe
@param buffer
the buffer to copy the hypothesis to
@return the length of the buffer
Gets the current state of signals for the sigframe @param buffer the buffer to copy the hypothesis to @return the length of the buffer
int stt_listen(char *buffer) {
  int found;
  int bytesread;
  found = 0;
  while ((bytesread = read(lisfd[0], interim, 127)) > 0) {
    int i;
    interim[bytesread] = '\0';
    if (bufindex + bytesread >= sizeof(readbuf)) {
      memmove(readbuf, &readbuf[128], 128);
    }
    for (i = 0; i < bytesread; i++) {
      if (interim[i] == '\n') {
        if (strncmp(readbuf, "hypothesis:", 11) == 0) {
          bufindex -= 13;
          strncpy(phrase, &readbuf[12], bufindex);
          phrase[bufindex] = '\0';
          found = 1;
        }
        bufindex = 0;
      } else {
        readbuf[bufindex] = interim[i];
        if (interim[i] != '\0') {
          bufindex++;
        }
      }
      readbuf[bufindex] = '\0';
    }
  }
  if (found) {
    strcpy(buffer, phrase);
    return strlen(phrase);
  } else {
    return 0;
  }
}
int stt_listen ( char * buffer ) { int found ; int bytesread ; found = 0 ; while ( ( bytesread = read ( lisfd [ 0 ] , interim , 127 ) ) > 0 ) { int i ; interim [ bytesread ] = ' \0 ' ; if ( bufindex + bytesread >= sizeof ( readbuf ) ) { memmove ( readbuf , & readbuf [ 128 ] , 128 ) ; } for ( i = 0 ; i < bytesread ; i ++ ) { if ( interim [ i ] == ' \n ' ) { if ( strncmp ( readbuf , " " , 11 ) == 0 ) { bufindex -= 13 ; strncpy ( phrase , & readbuf [ 12 ] , bufindex ) ; phrase [ bufindex ] = ' \0 ' ; found = 1 ; } bufindex = 0 ; } else { readbuf [ bufindex ] = interim [ i ] ; if ( interim [ i ] != ' \0 ' ) { bufindex ++ ; } } readbuf [ bufindex ] = ' \0 ' ; } } if ( found ) { strcpy ( buffer , phrase ) ; return strlen ( phrase ) ; } else { return 0 ; } }
Gets the current state of signals for the sigframe
  @param buffer
    the buffer to copy the hypothesis to
  @return the length of the buffer
Gets the current state of signals for the sigframe @param buffer the buffer to copy the hypothesis to @return the length of the buffer
// state machine