static int setkeymapping_js(int i, int keypr) { int b, b2; while (!(b = js_readbtn(i))) { if (inputdevs_fd[i+1] == -1) return STARTBTN; if (b = getkeypress_select(100, SINGLE_PL)) { if (b == ESC) { js_rmmapping(i, keypr); return MVDOWN; } return b; } sleep_msec(55); } b2 = js_readbtn(i); if (b > b2 && b2) b = b2; if (!key_is_valid(b, keypr)) return b; if (b == MVUP && keypr == MVUP && js_getbtnfor(i, MVUP) == MVUP) return MVUP; js_setmapping(i, b, keypr); return MVDOWN; }
static int setkeymapping_keybd(int keypr) { unsigned char s[5] = ""; unsigned c; kb_no_autorep = 1; while (!kb_readkey(s)) { if (c = getkeypress_select(100, SINGLE_PL)) return c; sleep_msec(55); } c = !s[1] ? s[0] : ESC+1; if (c == ESC) kb_rmmapping(keypr); else { if (!key_is_valid(c, keypr)) return c; if (c == MVUP && (keypr & (63 | IN_GAME)) == MVUP) { c = kb_getchrfor(keypr); if (c == MVUP) return MVUP; } kb_setmapping(s, keypr); if (!c && (!(keypr & PLAYER_2) || inputdevs_player[0]==2)) return MVUP; } return MVDOWN; }
int getkeypress(int tm, int flags) { int t = gettm(0); int keypress; if (socket_fd > -1) flags |= SINGLE_PL; while (1) { if (tm <= 0) return 0; keypress = getkeypress_select(tm, flags); #if JOYSTICK if (!keypress) keypress = getautorepeat(flags); #endif if (keypress) break; if (gettm(t) == t) sleep_msec(1); tm -= gettm(t)-t; t = gettm(0); #ifdef ALLEGRO if (close_button_pressed) exit(0); #endif } return keypress; }
bool ev3_connect( void ) { if ( ev3_udp_connect() != EOF ) { int i; for ( i = 0; i < 10; i++ ) { sleep_msec( 1000 ); if ( ev3_udp_catch_address() > 0 ) break; } ev3_udp_disconnect(); } if ( ev3_tcp_connect() == EOF ) return ( false ); if ( ev3_tcp_unlock_request() == EOF ) return ( false ); sleep_msec( 100 ); ev3_tcp_unlock_reply(); return ( true ); }
bool sensor_value( uint8_t port, void *buf ) { size_t globals = 1; uint8_t lmc[] = { opINPUT_READ, LC0( 0 ), LC0( port ), LC0( 0 ), LC0( 0 ), GV0( 0 ) }; int n = ev3_tcp_direct( 1, 0, lmc, sizeof( lmc ), DIRECT_COMMAND_REPLY ); if ( n == EOF ) return ( false ); sleep_msec( 100 ); return ( ev3_tcp_direct_reply( n, buf, &globals ) == DIRECT_REPLY ); }
void test_time() { ulong t2, t1 = get_time_ms(); sleep_msec(1234); /* don't remove 1234, cause it tests overflow of tv.tv_nsec */ t2 = get_time_ms() - t1; assert(t2 >= 1234); fprintf(stdout, "%s:\tpassed\n", __FUNCTION__); }
int main( int argc, char **argv ) { char buf[ 256 ]; uint8_t val; if ( !ev3_connect()) return ( 1 ); tacho_start( OUT_ALL, 20 ); sleep_msec( 2000 ); tacho_stop( OUT_ALL ); sleep_msec( 100 ); if ( sensor_name( IN_1, buf )) printf( "IN_1 '%s'\n", buf ); sleep_msec( 100 ); if ( sensor_value( IN_1, &val )) printf( "IN_1 value = %d\n", val ); ev3_tcp_disconnect(); return ( 0 ); }
int getkeypress_block(int flags) { int keypress; while (1) { #if TTY_SOCKET && !NO_MENU if (!(flags & 1) && (invit || checkinvit())) return ESC; #endif keypress = getkeypress(1000, flags); if (keypress) break; sleep_msec(55); } return keypress; }
static int read_audio_adev(int16 * buf, int len) { int k; if (!ad) { E_FATAL("Failed to read audio from mic\n"); return -1; } while ((k = ad_read(ad, buf, len)) == 0) /* wait until something is read */ sleep_msec(50); return k; }
/* * Main utterance processing loop: * for (;;) { * start utterance and wait for speech to process * decoding till end-of-utterance silence will be detected * print utterance result; * } */ static void recognize_from_microphone() { ad_rec_t *ad; int16 adbuf[2048]; uint8 utt_started, in_speech; int32 k; char const *hyp; if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int) cmd_ln_float32_r(config, "-samprate"))) == NULL) E_FATAL("Failed to open audio device\n"); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if (ps_start_utt(ps) < 0) E_FATAL("Failed to start utterance\n"); utt_started = FALSE; E_INFO("Ready....\n"); for (;;) { if ((k = ad_read(ad, adbuf, 2048)) < 0) E_FATAL("Failed to read audio\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); in_speech = ps_get_in_speech(ps); if (in_speech && !utt_started) { utt_started = TRUE; E_INFO("Listening...\n"); } if (!in_speech && utt_started) { /* speech -> silence transition, time to start new utterance */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL ); if (hyp != NULL) { printf("%s\n", hyp); fflush(stdout); } if (ps_start_utt(ps) < 0) E_FATAL("Failed to start utterance\n"); utt_started = FALSE; E_INFO("Ready....\n"); } sleep_msec(100); } ad_close(ad); }
static void recognize_from_microphone() { ad_rec_t *ad; int16 adbuf[2048]; uint8 utt_started, in_speech; int32 k; char const *hyp; if ((ad = ad_open_dev(AUDIO_DEVICE_NAME, (int) SAMPLE_RATE )) == NULL) { E_FATAL("Failed to open audio device\n"); } if (ad_start_rec(ad) < 0) { E_FATAL("Failed to start recording\n"); } if (ps_start_utt(ps) < 0) { E_FATAL("Failed to start utterance\n"); } utt_started = FALSE; printf("READY....\n"); for (;;) { if ((k = ad_read(ad, adbuf, 2048)) < 0) E_FATAL("Failed to read audio\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); in_speech = ps_get_in_speech(ps); if (in_speech && !utt_started) { utt_started = TRUE; printf("Listening...\n"); } if (!in_speech && utt_started) { /* speech -> silence transition, time to start new utterance */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL ); if (hyp != NULL) printf("%s\n", hyp); if (ps_start_utt(ps) < 0) E_FATAL("Failed to start utterance\n"); utt_started = FALSE; printf("READY....\n"); } sleep_msec(100); } ad_close(ad); }
/* * Main utterance processing loop: * for (;;) { * wait for start of next utterance; * decode utterance until silence of at least 1 sec observed; * print utterance result; * } */ static void recognize_from_microphone(int outfd) { int16 adbuf[4096]; int32 k, ts, rem; char const *hyp; char const *uttid; char word[4096]; if ((ad = ad_open_dev(NULL, (int)cmd_ln_float32_r(config, "-adcdev"))) == NULL) E_FATAL("Failed to open audio device\n"); /* Initialize continuous listening module */ if ((cont = cont_ad_init(ad, ad_read)) == NULL) E_FATAL("Failed to initialize voice activity detection\n"); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if (cont_ad_calib(cont) < 0) E_FATAL("Failed to calibrate voice activity detection\n"); for (;;) { /* Indicate listening for next utterance */ write(outfd, "READY\n", 6); /* Wait data for next utterance */ while ((k = cont_ad_read(cont, adbuf, 4096)) == 0) sleep_msec(100); if (k < 0) E_FATAL("Failed to read audio\n"); /* * Non-zero amount of data received; start recognition of new utterance. * NULL argument to uttproc_begin_utt => automatic generation of utterance-id. */ if (ps_start_utt(ps, NULL) < 0) E_FATAL("Failed to start utterance\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); write(outfd, "Listening\n", 10); /* 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("Failed to read audio\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. */ rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE); /* 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); /* Finish decoding, obtain and print result */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL, &uttid); snprintf(word, sizeof(word)-1, "%s: %s\n", uttid, hyp); write(outfd, word, strlen(word)); /* Resume A/D recording for next utterance */ if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); } cont_ad_close(cont); ad_close(ad); fprintf (stderr, "listen thread exiting\n"); }
/* * Main utterance processing loop: * for (;;) { * start utterance and wait for speech to process * decoding till end-of-utterance silence will be detected * print utterance result; * } */ static void recognize_from_microphone() { //---------------------definitions ad_rec_t *ad; int16 adbuf[2048]; uint8 utt_started, in_speech; int32 k; char const *hyp; ///////////////////////////// if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int) cmd_ln_float32_r(config, "-samprate"))) == NULL) E_FATAL("Failed to open audio device\n"); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if (ps_start_utt(ps) < 0) E_FATAL("Failed to start utterance\n"); utt_started = FALSE; printf("READY1....\n"); for (;;) { if ((k = ad_read(ad, adbuf, 2048)) < 0) E_FATAL("Failed to read audio\n"); // decode whatever data was read //1.try to limit the processing time here //2.Or modify the algorithm //3.Or change the parameters of the implemented functions ps_process_raw(ps, adbuf, k, FALSE, FALSE); in_speech = ps_get_in_speech(ps); if (in_speech && !utt_started) { //machine processing acoustics (listening) utt_started = TRUE; printf("Listening...\n"); } if (!in_speech && utt_started) { //--------------------------------------------understanding without listening /* speech -> silence transition, time to start new utterance */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL ); if (hyp != NULL) { rawfd = fopen("char-array.txt", "a"); //~ fprintf(rawfd, "data\n"); //~ fclose(rawfd); if (hyp) { strcpy(word0, ""); strcpy(word1, ""); sscanf(hyp, "%s", word0); printf("%s\n", word0); } //~ printf("%s\n", hyp); // this appears on the screan fprintf(rawfd, "%s\n",hyp); // write to txt file fclose(rawfd); printf("xxxxx"); } if (ps_start_utt(ps) < 0) //open the file and start decoding E_FATAL("Failed to start utterance\n"); utt_started = FALSE; printf("READY2....\n"); const char *text = "write this to the file"; // fprintf(f,"some text :%s\n",text); // fclose(f); } sleep_msec(1); } ad_close(ad); }
/* * Main utterance processing loop: * for (;;) { * wait for start of next utterance; * decode utterance until silence of at least 1 sec observed; * print utterance result; * } */ static void utterance_loop() { int16 adbuf[4096]; int32 k, ts, rem, score; char const *hyp; char const *uttid; cont_ad_t *cont; 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(100); 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 (ps_start_utt(ps, NULL) < 0) E_FATAL("ps_start_utt() failed\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); 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. */ rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE); /* 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); /* Finish decoding, obtain and print result */ ps_end_utt(ps); hyp = ps_get_hyp(ps, &score, &uttid); printf("%s: %s (%d)\n", uttid, hyp, score); fflush(stdout); /* Exit if the first word spoken was GOODBYE */ if (hyp) { sscanf(hyp, "%s", word); if (strcmp(word, "goodbye") == 0) break; } /* 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(int argc, char *argv[]) { char const *cfg; int i; int16 buf[2048]; if (argc == 2) { config = cmd_ln_parse_file_r(NULL, cont_args_def, argv[1], TRUE); } else { config = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, FALSE); } /* Handle argument file as -argfile. */ if (config && (cfg = cmd_ln_str_r(config, "-argfile")) != NULL) { config = cmd_ln_parse_file_r(config, cont_args_def, cfg, FALSE); } if (config == NULL) return 1; singlefile = cmd_ln_boolean_r(config, "-singlefile"); if ((infile_path = cmd_ln_str_r(config, "-infile")) != NULL) { if ((infile = fopen(infile_path, "rb")) == NULL) { E_FATAL_SYSTEM("Failed to read audio from '%s'", infile_path); return 1; } read_audio = &read_audio_file; /* skip wav header */ read_audio(buf, 44); } else { if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int) cmd_ln_float32_r(config, "-samprate"))) == NULL) { E_FATAL("Failed to open audio device\n"); return 1; } read_audio = &read_audio_adev; printf("Start recording ...\n"); fflush(stdout); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); /* TODO remove this thing */ for (i = 0; i < 5; i++) { sleep_msec(200); read_audio(buf, 2048); } printf("You may speak now\n"); fflush(stdout); } fe = fe_init_auto_r(config); if (fe == NULL) return 1; segment_audio(); if (ad) ad_close(ad); if (infile) fclose(infile); fe_free(fe); cmd_ln_free_r(config); return 0; }
/* * Main utterance processing loop: * for (;;) { * wait for start of next utterance; * decode utterance until silence of at least 1 sec observed; * print utterance result; * } */ static void recognize_from_microphone() { ad_rec_t *ad; int16 adbuf[4096]; int32 k, ts, rem; char const *hyp; char const *uttid; cont_ad_t *cont; char word[256]; char c1[256], c2[256]; int tracking = 0; int halted = 0; int LEFT = 0; int RIGHT = 1; int MOVE_CENT = 100; //1 meter int numwords; setlinebuf(stdout); if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) E_FATAL("Failed to open audio device\n"); /* Initialize continuous listening module */ if ((cont = cont_ad_init(ad, ad_read)) == NULL) E_FATAL("Failed to initialize voice activity detection\n"); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if (cont_ad_calib(cont) < 0) E_FATAL("Failed to calibrate voice activity detection\n"); printf("LEDON BLUE\n"); for (;;) { /* Indicate listening for next utterance */ fprintf(stderr, "READY....\n"); fflush(stderr); /* Wait data for next utterance */ while ((k = cont_ad_read(cont, adbuf, 4096)) == 0) sleep_msec(100); if (k < 0) E_FATAL("Failed to read audio\n"); /* * Non-zero amount of data received; start recognition of new utterance. * NULL argument to uttproc_begin_utt => automatic generation of utterance-id. */ if (ps_start_utt(ps, NULL) < 0) E_FATAL("Failed to start utterance\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); fprintf(stderr, "Listening...\n"); /* 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("Failed to read audio\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. */ rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE); /* 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); fprintf(stderr, "Stopped listening, please wait...\n"); fflush(stdout); /* Finish decoding, obtain and print result */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL, &uttid); fprintf(stderr, "%s: %s\n", uttid, hyp); /* Exit if the first word spoken was GOODBYE */ if (hyp) { numwords = sscanf(hyp, "%s %s %s", word, c1, c2); if(strcmp(word, "GUGGUG") == 0) { if(strcmp(c1, "HALT") == 0) { printf("LEDOFF BLUE\n"); halted = 1; } else if(strcmp(c1, "RESUME") == 0) { printf("LEDON BLUE\n"); halted = 0; } if(strcmp(c1, "BEGIN") == 0 || strcmp(c1, "START") == 0) { if(strcmp(c2, "TRACKING") == 0 && !tracking) { printf("START TRACKING\n"); tracking = 1; halted = 0; } } else if(strcmp(c1, "STOP") == 0) { if(strcmp(c2, "TRACKING") == 0 && tracking) { printf("STOP TRACKING\n"); tracking = 0; } } if(!tracking && !halted && numwords == 3) { if(strcmp(c1, "TURN") == 0) { if(strcmp(c2, "AROUND") == 0) { printf("TURN %d 180\n", LEFT); } else if(strcmp(c2, "LEFT") == 0) { printf("TURN %d 90\n", LEFT); } else if(strcmp(c2, "RIGHT") == 0) { printf("TURN %d 90\n", RIGHT); } } else if(strcmp(c1, "MOVE") == 0) { if(strcmp(c2, "FORWARD") == 0) { printf("MOVE 0 %d\n", MOVE_CENT); } else if(strcmp(c2, "BACKWARD") == 0) { printf("MOVE 1 %d\n", MOVE_CENT); } } } } } /* Resume A/D recording for next utterance */ if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); } cont_ad_close(cont); ad_close(ad); }
void listen::recognize_from_microphone(){ ad_rec_t *ad; int16 adbuf[4096]; int32 k, ts, rem; char buffer[128]; char const *hyp; char const *uttid; cont_ad_t *cont; state = SLEEPING; FILE* pipe = popen(c.getValue("[General]", "Hcidump").c_str(), "r"); std::string bufferStr; std::size_t found; if((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) E_FATAL("Failed to open audio device\n"); /* Initialize continuous listening module */ if((cont = cont_ad_init(ad, ad_read)) == NULL) E_FATAL("Failed to initialize voice activity detection\n"); if(ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if(cont_ad_calib(cont) < 0) E_FATAL("Failed to calibrate voice activity detection\n"); while(!feof(pipe) || state == SLEEPING){ fgets(buffer, 128, pipe); bufferStr = buffer; found = bufferStr.find(c.getValue("[General]", "KeyPress")); if(found!=std::string::npos){ i.pauseIfPlaying(); s.speakThis(c.getValue("[General]", "WakeUpPhrase")); state = ACTIVE; while(state != SLEEPING){ /* Indicate listening for next utterance */ printf("READY....\n"); fflush(stdout); fflush(stderr); /* Wait data for next utterance */ while ((k = cont_ad_read(cont, adbuf, 4096)) == 0){ sleep_msec(100); } if (k < 0) E_FATAL("Failed to read audio\n"); /* * Non-zero amount of data received; start recognition of new utterance. * NULL argument to uttproc_begin_utt => automatic generation of utterance-id. */ if (ps_start_utt(ps, NULL) < 0) E_FATAL("Failed to start utterance\n"); ps_process_raw(ps, adbuf, k, FALSE, FALSE); 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(;;){ //while(sleep(2)){ /* Read non-silence audio data, if any, from continuous listening module */ if ((k = cont_ad_read(cont, adbuf, 4096)) < 0) E_FATAL("Failed to read audio\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. */ rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE); /* 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); /* Finish decoding, obtain and print result */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL, &uttid); fflush(stdout); /* Resume A/D recording for next utterance */ if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); if(hyp != NULL){ if(hyp == c.getValue("[General]", "Sleep")){ state = SLEEPING; s.speakThis(c.getValue("[General]", "SleepPhrase")); }else{ if(state != SLEEPING){ i.parse(hyp); } //Hack for play/pause/select std::string hypStr = hyp; if(hypStr == "PLAY ITEM" || hypStr == "PAUSE ITEM" || hypStr == "SELECT ITEM"){ state = SLEEPING; } } } } } } pclose(pipe); cont_ad_close(cont); ad_close(ad); }
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); }
void start() { GUARD_THREAD_START(_hasStopped); _stop = false; struct timeval selectTime; fd_set rfds; int selectResult = 0; int prevSelectResult = selectResult; bool deletedWatchDirectory = false; while (!_stop && !deletedWatchDirectory) { FD_ZERO(&rfds); FD_SET(_inotifyFD, &rfds); selectTime.tv_sec = 0; selectTime.tv_usec = _pollUSec; selectResult = select(_inotifyFD + 1, &rfds, NULL, NULL, &selectTime); if (selectResult < 0) { if (errno == EINTR) { // we sometimes get interrupted by signals - try again continue; } if (selectResult != prevSelectResult) { // log warning the first time the error occurs Logging::warning("Select error in directory watch: %s\n", strerror(errno)); } // don't hog the CPU when select errors occur sleep_msec(500); } else if (selectResult && FD_ISSET(_inotifyFD, &rfds)) { #define EVENT_SIZE (sizeof(struct inotify_event)) #define BUF_LEN (1024 * (EVENT_SIZE + 16)) char buf[BUF_LEN]; int len, i = 0; len = read(_inotifyFD, buf, BUF_LEN); if (len < 0) { Logging::error("Failed to read inotify events: %s\n", strerror(errno)); } else if (len == 0) { Logging::error("Failed to read inotify events - buffer could be too small\n"); } else { while (i < len) { struct inotify_event* event; event = (struct inotify_event*)&buf[i]; if (event->wd != _watch) { continue; } if (event->mask & IN_DELETE_SELF) { _directoryWatch->sendThisDirectoryDeletion(_directory); // end of the line deletedWatchDirectory = true; } if (event->mask & IN_DELETE) { _directoryWatch->sendDeletion(_directory, event->name); } if (event->mask & IN_CREATE) { _directoryWatch->sendCreation(_directory, event->name); } if (event->mask & IN_MODIFY) { _directoryWatch->sendModification(_directory, event->name); } if (event->mask & IN_MOVED_FROM) { _directoryWatch->sendMovedFrom(_directory, event->name); } if (event->mask & IN_MOVED_TO) { _directoryWatch->sendMovedTo(_directory, event->name); } i += EVENT_SIZE + event->len; } } } prevSelectResult = selectResult; } }
bool_t draw_space( bool_t flg_draw_staff_roll ) { long sx, sy, sw, sh; long mx, my; long fl; long max_n, i; move_space(); g_frame++; do { if( !flg_draw_staff_roll ) break; if( get_scene() != SCENE_N_ENDING_STAFF_ROLL ) break; if( (g_frame % g_roll_frame_n) != 0 ) break; staff_roll_y += 1; wipe_all(); break; } while( 0 ); sx = 0; sy = 0; sw = SCREEN_WIDTH; sh = SCREEN_HEIGHT; mx = sx + sw / 2; my = sy + sh / 2; max_n = get_star_n(); fl = max_n / FLICKER_N; if( fl < 1 ) fl = 1; for( i = 0; i < max_n; i++ ){ long drx, dry; long zz; zz = g_space.star[i].z + 1; drx = mx + g_space.star[i].x / zz / 16; dry = my + g_space.star[i].y / zz / 32; wipe_star( g_space.star[i].drx, g_space.star[i].dry ); if( dry < sh ) draw_star( drx, dry, zz ); g_space.star[i].drx = drx; g_space.star[i].dry = dry; if( (i % fl) == 0 ) if( flg_draw_staff_roll ) draw_staff_roll(); } if( flg_draw_staff_roll ) draw_staff_roll(); set_crsr( 0, 0 ); sleep_msec( 100 ); return TRUE; }