static void gst_pocketsphinx_process_chunk (GstPocketSphinx *sphinxsink) { int32 k; int16 adbuf[REQUIRED_FRAME_SAMPLES]; k = cont_ad_read (sphinxsink->cont, adbuf, REQUIRED_FRAME_SAMPLES); if (k == 0 && sphinxsink->last_ts == 0) { return; } else if (k == 0 && sphinxsink->cont->read_ts - sphinxsink->last_ts > DEFAULT_SAMPLES_PER_SEC) { int32 fr; char *hyp = NULL; uttproc_end_utt (); if (uttproc_result (&fr, &hyp, 1) < 0) { g_warning ("uttproc_result failed"); } else { if (hyp != NULL) g_signal_emit (sphinxsink, gst_pocketsphinx_signals[SIGNAL_RESULT], 0, hyp); } sphinxsink->last_ts = 0; sphinxsink->ad.listening = 0; g_signal_emit (sphinxsink, gst_pocketsphinx_signals[SIGNAL_READY], 0, NULL); } else if (k != 0) { if (sphinxsink->ad.listening == 0) { uttproc_begin_utt (NULL); sphinxsink->ad.listening = 1; g_signal_emit (sphinxsink, gst_pocketsphinx_signals[SIGNAL_LISTENING], 0, NULL); } uttproc_rawdata (adbuf, k, 1); sphinxsink->last_ts = sphinxsink->cont->read_ts; } }
static void utterance_loop(int argc,char *argv[]) { int16 adbuf[4096]; int32 k, fr, ts, rem; char *hyp; cont_ad_t *cont; int count=0,i=1,flag; char word[256]; /* Initialize continuous listening module */ if ((cont = cont_ad_init (ad, ad_read)) == NULL) E_FATAL("cont_ad_init failed\n"); if (ad_start_rec (ad) < 0) E_FATAL("ad_start_rec failed\n"); if (cont_ad_calib (cont) < 0) E_FATAL("cont_ad_calib failed\n"); for (;;) { /* Indicate listening for next utterance */ printf ("READY....\n"); fflush (stdout); fflush (stderr); /* Await data for next utterance */ while ((k = cont_ad_read (cont, adbuf, 4096)) == 0) sleep_msec(200); if (k < 0) E_FATAL("cont_ad_read failed\n"); /* * Non-zero amount of data received; start recognition of new utterance. * NULL argument to uttproc_begin_utt => automatic generation of utterance-id. */ if (uttproc_begin_utt (NULL) < 0) E_FATAL("uttproc_begin_utt() failed\n"); uttproc_rawdata (adbuf, k, 0); printf ("Listening...\n"); fflush (stdout); /* Note timestamp for this first block of data */ ts = cont->read_ts; /* Decode utterance until end (marked by a "long" silence, >1sec) */ for (;;) { /* Read non-silence audio data, if any, from continuous listening module */ if ((k = cont_ad_read (cont, adbuf, 4096)) < 0) E_FATAL("cont_ad_read failed\n"); if (k == 0) { /* * No speech data available; check current timestamp with most recent * speech to see if more than 1 sec elapsed. If so, end of utterance. */ if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC) break; } else { /* New speech data received; note current timestamp */ ts = cont->read_ts; } /* * Decode whatever data was read above. NOTE: Non-blocking mode!! * rem = #frames remaining to be decoded upon return from the function. */ rem = uttproc_rawdata (adbuf, k, 0); /* If no work to be done, sleep a bit */ if ((rem == 0) && (k == 0)) sleep_msec (20); } /* * Utterance ended; flush any accumulated, unprocessed A/D data and stop * listening until current utterance completely decoded */ ad_stop_rec (ad); while (ad_read (ad, adbuf, 4096) >= 0); cont_ad_reset (cont); printf ("Stopped listening, please wait...\n"); fflush (stdout); #if 0 /* Power histogram dump (FYI) */ cont_ad_powhist_dump (stdout, cont); #endif /* Finish decoding, obtain and print result */ uttproc_end_utt (); if (uttproc_result (&fr, &hyp, 1) < 0) E_FATAL("uttproc_result failed\n"); /*obtaining the results*/ sscanf (hyp, "%s", word); printf ("%d: %s\n", fr,word); fflush (stdout); win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); i=g_list_index(tmp,win);/*the place value of window in the list*/ printf("<<<<<<<<<<<<<<>>>>>>>>>>>>>>i:%d,%s\n\n\n",i,wnck_window_get_name(win)); count=0; while(tmp!=NULL) { printf("%d:%s\n\n",count,wnck_window_get_name(tmp->data)); tmp=tmp->next;count++; } /*comparison and action for DAKKU */ if(strcmp(word,"PADU")==0) g_spawn_command_line_async("totem --play",NULL); if(strcmp(word,"EMACS")==0) g_spawn_command_line_async("emacs",NULL); if(strcmp(word,"SAMAYAM")==0) g_spawn_command_line_async(DHVANISCRIPT,NULL); if(strcmp(word,"VALAPARATHU")==0) g_spawn_command_line_async("epiphany",NULL); if(strcmp(word,"EAZHUTHIDAM")==0) g_spawn_command_line_async("gedit",NULL); /*Minimizing current active window*/ if (strcmp (word, "CHURUKKU") == 0) wnck_window_minimize(win); /*Moving focus(active window)towards the left of the panel.The active window is changed to the next normal window on the left.effect of alt+tab key press*/ if(strcmp(word,"ADUTHATHU")==0) { win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); while(tmp!=NULL)/*while traces the current active window through the list*/ { printf("tracing:current:%s\n\ntmp:%s\n\n",wnck_window_get_name(win),wnck_window_get_name(tmp->data)); if(tmp->data==win) { printf("BREAKED with tmp:%s\n",wnck_window_get_name(tmp->data)); break; } tmp=tmp->next; } if(tmp==NULL){printf("BULL SHIT GIVE A WINDOW IN THE LIST\n\n");}//exit(1);} if(tmp->next==NULL)/*shifting back to the first window by refreshing the list*/ tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); else tmp=tmp->next; printf("cuow:%s\n\n",wnck_window_get_name(tmp->data)); while(tmp!=NULL) { printf("tmp in while:%s\n\n",wnck_window_get_name(tmp->data)); if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL) { wnck_window_activate(tmp->data,0); flag=1; break; } else tmp=tmp->next; } if(flag==0) { printf("FLAG==0 DETECTED:\n"); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); while(tmp!=NULL) { printf("tmp in last while:%s\n",wnck_window_get_name(tmp->data)); if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL) { wnck_window_activate(tmp->data,0); break; } else tmp=tmp->next; } } } if(strcmp(word,"VALUTHAKKU")==0) { if(wnck_window_get_window_type(win)!= WNCK_WINDOW_NORMAL) { if(wnck_window_get_window_type(wnck_screen_get_previously_active_window(scr))==WNCK_WINDOW_NORMAL) win=wnck_screen_get_previously_active_window(scr); } wnck_window_unminimize(win,0); } while(gtk_events_pending())/*gtk probing and refreshing the win and tmp*/ { gtk_main_iteration(); win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); } /* Resume A/D recording for next utterance */ if (ad_start_rec (ad) < 0) E_FATAL("ad_start_rec failed\n"); } cont_ad_close (cont); }
int main (int32 argc, char *argv[]) { char line[4096], filename[4096], idspec[4096], *uttid, *result; int32 sf, ef, sps, adcin, nf; int16 adbuf[4096]; int32 i, k; float32 **mfcbuf; CDCN_type *cdcn; param_t param; fe_t *fe = NULL; fbs_init (argc, argv); /* Assume that cdcn_init is part of the above fbs_init() */ cdcn = uttproc_get_cdcn_ptr(); adcin = query_adc_input(); assert (adcin); /* Limited to processing audio input files (not cep) */ sps = query_sampling_rate(); fe_init_params(¶m); param.SAMPLING_RATE = (float)sps; if ((fe = fe_init (¶m)) == NULL) { E_ERROR("fe_init() failed to initialize\n"); exit (-1); } mfcbuf = (float32 **) ckd_calloc_2d (8192, 13, sizeof(float32)); /* Process "control file" input through stdin */ while (fgets (line, sizeof(line), stdin) != NULL) { if (uttproc_parse_ctlfile_entry (line, filename, &sf, &ef, idspec) < 0) continue; assert ((sf < 0) && (ef < 0)); /* Processing entire input file */ uttid = build_uttid (idspec); uttproc_begin_utt (uttid); /* Convert raw data file to cepstra */ if (uttfile_open (filename) < 0) { E_ERROR("uttfile_open(%s) failed\n", filename); continue; } fe_start_utt(fe); nf = 0; while ((k = adc_file_read (adbuf, 4096)) >= 0) { if (fe_process_utt (fe, adbuf, k, mfcbuf+nf, &k) == FE_ZERO_ENERGY_ERROR) { E_WARN("Frames with zero energy. Consider using dither\n"); } nf += k; /* WARNING!! No check for mfcbuf overflow */ } fe_end_utt(fe, mfcbuf[nf], &k); fe_close(fe); uttfile_close (); if (nf <= 0) { E_ERROR("Empty utterance\n"); continue; } else E_INFO("%d frames\n", nf); /* Update CDCN module */ cdcn_converged_update (mfcbuf, /* cepstra buffer */ nf, /* Number of frames */ cdcn, /* The CDCN wrapper */ 1 /* One iteration */ ); /* CDCN */ for (i = 0; i < nf; i++) cdcn_norm (mfcbuf[i], cdcn); /* Process normalized cepstra */ uttproc_cepdata (mfcbuf, nf, 1); uttproc_end_utt (); uttproc_result (&k, &result, 1); printf ("\n"); fflush (stdout); } ckd_free_2d((void **)mfcbuf); fbs_end (); return 0; }