speech/speech-to-text/stt.c
int stt_start_listening(void) {
  if (!lisinit) {
    lisinit = 1;
    // start pocketsphinx process (to get rid of stderr)
    if (pipe(lisfd) == -1) {
      fprintf(stderr, "[stt] Error: cannot create the listener pipe\n");
      return -1;
    }
    lispid = fork();
    if (lispid == 0) {
      close(1);
      if (dup(lisfd[1]) == -1) {
        fprintf(stderr, "[stt] {child} Warning: cannot redirect listener output\n");
        exit(1);
      }
      close(2); // stop seeing stderr INFO
      execlp("./listen", "listen", NULL);
      printf("[stt] {child} Error: bad ps subprocess exec\n");
      exit(1);
    } else if (lispid > 0) {
      // make read nonblocking
      int flags;
      flags = fcntl(lisfd[0], F_GETFL, 0);
      fcntl(lisfd[0], F_SETFL, flags | O_NONBLOCK);
    } else {
      fprintf(stderr, "[stt] Error: could not create ps subprocess\n");
      return -1;
    }
    return 0;
  }
  return -1;
}
/** Start recording
 *  @return 0 on success, otherwise -1
 */
Start recording
@return 0 on success, otherwise -1
Start recording @return 0 on success otherwise - 1
int stt_start_listening(void) {
  if (!lisinit) {
    lisinit = 1;
    if (pipe(lisfd) == -1) {
      fprintf(stderr, "[stt] Error: cannot create the listener pipe\n");
      return -1;
    }
    lispid = fork();
    if (lispid == 0) {
      close(1);
      if (dup(lisfd[1]) == -1) {
        fprintf(stderr, "[stt] {child} Warning: cannot redirect listener output\n");
        exit(1);
      }
      close(2); 
      execlp("./listen", "listen", NULL);
      printf("[stt] {child} Error: bad ps subprocess exec\n");
      exit(1);
    } else if (lispid > 0) {
      int flags;
      flags = fcntl(lisfd[0], F_GETFL, 0);
      fcntl(lisfd[0], F_SETFL, flags | O_NONBLOCK);
    } else {
      fprintf(stderr, "[stt] Error: could not create ps subprocess\n");
      return -1;
    }
    return 0;
  }
  return -1;
}
int stt_start_listening ( void ) { if ( ! lisinit ) { lisinit = 1 ; if ( pipe ( lisfd ) == -1 ) { fprintf ( stderr , " \n " ) ; return -1 ; } lispid = fork ( ) ; if ( lispid == 0 ) { close ( 1 ) ; if ( dup ( lisfd [ 1 ] ) == -1 ) { fprintf ( stderr , " \n " ) ; exit ( 1 ) ; } close ( 2 ) ; execlp ( " " , " " , NULL ) ; printf ( " \n " ) ; exit ( 1 ) ; } else if ( lispid > 0 ) { int flags ; flags = fcntl ( lisfd [ 0 ] , F_GETFL , 0 ) ; fcntl ( lisfd [ 0 ] , F_SETFL , flags | O_NONBLOCK ) ; } else { fprintf ( stderr , " \n " ) ; return -1 ; } return 0 ; } return -1 ; }
Start recording
  @return 0 on success, otherwise -1
Start recording @return 0 on success otherwise - 1
// start pocketsphinx process (to get rid of stderr) // stop seeing stderr INFO // make read nonblocking