Exemple #1
0
DWORD WINAPI
process_thread(LPVOID aParam)
{
  ad_rec_t *in_ad = 0;
  int16 samples[BUFSIZE];
  int32 num_samples;

  WaitForSingleObject(startEvent, INFINITE);

  in_ad = ad_open_sps(cmd_ln_int32 ("-samprate"));
  ad_start_rec(in_ad);

  while (WaitForSingleObject(finishEvent, 0) == WAIT_TIMEOUT) {
    num_samples = ad_read(in_ad, samples, BUFSIZE);
    if (num_samples > 0) {
      if (ld_utt_proc_raw(&decoder, samples, num_samples) < 0) {
	printf(">>>>> ld_utt_proc_raw() returned unexpectedly.\n");
	return -1;
      }
    }
  }

  ad_stop_rec(in_ad);
  ad_close(in_ad);

  if (ld_utt_end(&decoder)) {
    printf(">>>>> ld_utt_end() failed.\n");
    return -1;
  }

  return 0;
}
Exemple #2
0
int main (int argc, char *argv[])
{
    /* Make sure we exit cleanly (needed for profiling among other things) */
  g_shell_parse_argv(sphinx_command,&argc,&argv,NULL);
     gtk_init(&argc, &argv);
 
     scr = wnck_screen_get_default();
     while(gtk_events_pending()) gtk_main_iteration();
     win = wnck_screen_get_active_window(scr);
      tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
     signal(SIGINT, &sighandler);

    fbs_init (argc, argv);
    
    if ((ad = ad_open_sps (SAMPLE_RATE)) == NULL)
	E_FATAL("ad_open_sps failed\n");

    // E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);

    if (setjmp(jbuf) == 0) {
      utterance_loop (argc,argv);
    }

    fbs_end ();
    ad_close (ad);

    return 0;
}
THREAD_START
process_thread(void *aParam)
{
    ad_rec_t *in_ad = 0;
    int16 samples[BUFSIZE];
    int32 num_samples;

    cond_wait(startEvent);

    if ((in_ad = ad_open_sps((int) cmd_ln_float32("-samprate"))) == NULL) {
        printf("Failed to open audio input device\n");
        exit(1);
    }
    ad_start_rec(in_ad);

    while (cond_wait_timed(&finishEvent, TIMEOUT) == COND_TIMEDOUT) {
        num_samples = ad_read(in_ad, samples, BUFSIZE);
        if (num_samples > 0) {
      /** dump the recorded audio to disk */
            if (fwrite(samples, sizeof(int16), num_samples, dump) <
                num_samples) {
                printf("Error writing audio to dump file.\n");
            }

            ld_process_raw(&decoder, samples, num_samples);
        }
    }

    ad_stop_rec(in_ad);
    ad_close(in_ad);

    ld_end_utt(&decoder);

    return 0;
}
Exemple #4
0
/*
 * Wait for the user to type a <CR> then capture input audio for approx. 2 sec
 * and compute a measure of its power.
 */
int
main (int32 argc, char *argv[])
{
    char line[1024];
    ad_rec_t *ad;
    int16 buf[1000];
    int32 sps;
    
    sps = DEFAULT_SAMPLES_PER_SEC;

    if ((ad = ad_open_sps (sps)) == NULL)
	E_FATAL("ad_open_sps failed\n");
    
    for (;;) {
	printf ("Hit <CR> to measure A/D power; Q<CR> to quit: ");
	
	fgets (line, sizeof(line), stdin);
	if ((line[0] == 'q') || (line[0] == 'Q'))
	    break;
	
	ad_start_rec (ad);

	adpow(ad);
	
	ad_stop_rec (ad);
	while (ad_read (ad, buf, 1000) >= 0);	/* Flush any buffered, unread data */
    }

    ad_close (ad);
    return 0;
}
Exemple #5
0
/*
 * Record A/D data for approximately specified number of seconds into specified file.
 */
int
main (int32 argc, char *argv[])
{
    char line[1024];
    ad_rec_t *ad;
    int16 buf[1000];
    int32 len, k, sps;
    FILE *fp;
    
    if ((argc != 4) ||
	(sscanf (argv[1], "%d", &sps) != 1) ||
	(sscanf (argv[2], "%d", &len) != 1)) {
	E_FATAL("Usage: %s <sampling-rate> <#sec-to-record> <output-file>\n", argv[0]);
    }
    if ((fp = fopen (argv[3], "wb")) == NULL)
	E_FATAL("fopen(%s,wb) failed\n", argv[3]);
    
    len *= sps;		/* Convert to min. #samples to record */
    
    if ((ad = ad_open_sps (sps)) == NULL)
	E_FATAL("ad_open_sps(%d) failed\n", sps);
    
    printf ("Hit <CR> to start recording\n");
    fgets (line, sizeof(line), stdin);
    
    ad_start_rec (ad);
    
    /* Record desired no. of samples */
    while (len > 0) {
	/* Read A/D */
	if ((k = ad_read (ad, buf, 1000)) < 0)
	    E_FATAL("ad_read returned %d\n", k);

	/* Write data read, if any, to file (ad_read may return 0 samples) */
	if (k > 0) {
	    fwrite (buf, sizeof(int16), k, fp);
	    fflush (fp);
	    len -= k;
	}
    }
    
    ad_stop_rec (ad);
    ad_close (ad);

    fclose (fp);
    return 0;
}
Exemple #6
0
ad_rec_t *ad_open ( void )
{
  return ad_open_sps(DEFAULT_SAMPLES_PER_SEC);
}
Exemple #7
0
ad_rec_t *
ad_open(void)
{
    return (ad_open_sps(DEFAULT_SAMPLES_PER_SEC));      /* HACK!! Rename this constant */
}
Exemple #8
0
int
main(int argc, char **argv)
{
  live_decoder_t decoder;
  FILE *infile;
  ad_rec_t *ad;
  char *hypstr;
  int16 samples[BUFSIZE];
  int32 num_samples;
  int32 tot_samples = 0;

  if (argc < 2) {
    printf("Usage:  livedecoder2 [ARGS] INPUT_FILE\n");
    return -1;
  }

  if (ld_init(&decoder, argc - ((argc - 1) % 2), argv)) {
    printf("ld_init() failed.\n");
    return -1;
  }

  if (ld_utt_begin(&decoder, 0)) {
    printf("ld_utt_begin() failed.\n");
    return -1;
  }

  if (argc % 2) {
    /* record for 5 seconds */
    tot_samples = cmd_ln_int32 ("-samprate") * 5;
    ad = ad_open_sps(cmd_ln_int32 ("-samprate"));
    ad_start_rec(ad);
    while (tot_samples > 0) {
      num_samples = ad_read(ad, samples,
			    tot_samples > BUFSIZE ? BUFSIZE : tot_samples);
      if (num_samples > 0) {
	if (ld_utt_proc_raw(&decoder, samples, num_samples) < 0) {
	  printf("ld_utt_proc_raw() returned unexpectedly.\n");
	  return -1;
	}
	tot_samples -= num_samples;
      }
    }
    ad_stop_rec(ad);
    ad_close(ad);
  }
  else {
    infile = fopen(argv[1], "rb");
    while (!feof(infile)) {
      num_samples = fread(samples, sizeof(int16), BUFSIZE, infile);
      if (num_samples > 0) {
	if (ld_utt_proc_raw(&decoder, samples, num_samples) < 0) {
	  printf("ld_utt_proc_raw() returned unexpectedly.\n");
	  return -1;
	}
      }
    }
    fclose(infile);
  }
	
  if (ld_utt_end(&decoder)) {
    printf("ld_utt_end() failed.\n");
    return -1;
  }

  ld_utt_hyps(&decoder, &hypstr, 0);
  printf("decoder returned:\n%s\n", hypstr);

  return 0;
}