/** * <JA> * 録音されたサンプル列を処理するコールバック関数 * * @param now [in] 録音されたサンプル列 * @param len [in] 長さ(サンプル数) * * @return エラー時 -1,処理成功時 0,処理成功+区間終端検出時 1 を返す. * </JA> * <EN> * Callback handler of recorded sample fragments * * @param now [in] recorded fragments of speech sample * @param len [in] length of above in samples * * @return -1 on device error (require caller to exit and terminate input), * 0 on success (allow caller to continue), * 1 on succeeded but segmentation detected (require caller to exit but * input will continue in the next call. * </EN> */ static int adin_callback_file(SP16 *now, int len, Recog *recog) { int count; /* erase "<<<please speak>>>" text on tty at trigger up */ if (speechlen == 0) { fprintf(stderr, "\r \r"); } /* open output file for the first time */ if (use_raw) { if (fd == -1) { if (stout) { fd = 1; } else { if ((fd = open(filename, O_CREAT | O_RDWR #ifdef O_BINARY | O_BINARY #endif , 0644)) == -1) { perror("adinrec"); return -1; } } } } else { if (fp == NULL) { if ((fp = wrwav_open(filename, sfreq)) == NULL) { perror("adinrec"); return -1; } } } /* write recorded sample to file */ if (use_raw) { count = wrsamp(fd, now, len); if (count < 0) { perror("adinrec: cannot write"); return -1; } if (count < len * sizeof(SP16)) { fprintf(stderr, "adinrec: cannot write more %d bytes\ncurrent length = %d\n", count, speechlen * sizeof(SP16)); return -1; } } else { if (wrwav_data(fp, now, len) == FALSE) { fprintf(stderr, "adinrec: cannot write\n"); return -1; } } speechlen += len; /* progress bar in dots */ fprintf(stderr, "."); return(0); }
/** * <JA> * 録音されたサンプル列を処理するコールバック関数 * * @param now [in] 録音されたサンプル列 * @param len [in] 長さ(サンプル数) * * @return エラー時 -1,処理成功時 0,処理成功+区間終端検出時 1 を返す. * </JA> * <EN> * Callback handler of recorded sample fragments * * @param now [in] recorded fragments of speech sample * @param len [in] length of above in samples * * @return -1 on device error (require caller to exit and terminate input), * 0 on success (allow caller to continue), * 1 on succeeded but segmentation detected (require caller to exit but * input will continue in the next call. * </EN> */ static int adin_callback_file(SP16 *now, int len) { int count; /* it may be safe to limit the maximum record len for disk space */ /*if (speechlen + len > MAXSPEECHLEN) { fprintf(stderr, "Error: too long input (> %d samples)\n", MAXSPEECHLEN); return(FALSE); }*/ /* erase "<<<please speak>>>" text on tty at trigger up */ /* (moved from adin-cut.c) */ if (speechlen == 0) { j_printerr("\r \r"); } /* open output file for the first time */ if (use_raw) { if (fd == -1) { if (stout) { fd = 1; } else { if ((fd = creat(filename, 0644)) == -1) { perror("adinrec"); return -1; } } } } else { if (fp == NULL) { if ((fp = wrwav_open(filename, sfreq)) == NULL) { perror("adinrec"); return -1; } } } /* write recorded sample to file */ if (use_raw) { count = wrsamp(fd, now, len); if (count < 0) perror("adinrec: cannot write"); if (count < len * sizeof(SP16)) fprintf(stderr, "adinrec: cannot write more %d bytes\ncurrent length = %d\n", count, speechlen * sizeof(SP16)); } else { if (wrwav_data(fp, now, len) == FALSE) { fprintf(stderr, "adinrec: cannot write\n"); } } speechlen += len; /* progress bar in dots */ fprintf(stderr, "."); return(0); }
/** * <JA> * 読み込んだサンプル列を fd もしくは fp に記録 * するコールバック関数 * * @param now [in] 録音されたサンプル列 * @param len [in] 長さ(サンプル数) * * @return エラー時 -1,処理成功時 0,処理成功+区間終端検出時 1 を返す. * </JA> * <EN> * Callback handler to record the sample fragments to file pointed by * the file descriptor "fd". * * @param now [in] recorded fragments of speech sample * @param len [in] length of above in samples * * @return -1 on device error (require caller to exit and terminate input), * 0 on success (allow caller to continue), * 1 on succeeded but segmentation detected (require caller to exit but * input will continue in the next call. * </EN> */ static int adin_callback_file(SP16 *now, int len, Recog *recog) { int count; int start; int w; start = 0; if (recog->jconf->input.speech_input == SP_MIC && speechlen == 0) { /* this is first up-trigger */ if (rewind_msec > 0 && !recog->adin->is_valid_data) { /* not spoken currently but has data to process at first trigger */ /* it means that there are old spoken segments */ /* disgard them */ printf("disgard already recorded %d samples\n", len); return 0; } /* erase "<<<please speak>>>" text on tty */ fprintf(stderr, "\r \r"); if (rewind_msec > 0) { /* when -rewind value set larger than 0, the speech data spoken while pause will be considered back to the specified msec. */ printf("buffered samples=%d\n", len); w = rewind_msec * sfreq / 1000; if (len > w) { start = len - w; len = w; } else { start = 0; } printf("will process from %d\n", start); } } /* open files for recording at first trigger */ if (speech_output == SPOUT_FILE && speechlen == 0) { if (continuous_segment) { if (use_raw) { sprintf(outpath, "%s.%04d.raw", filename, sid); } else { sprintf(outpath, "%s.%04d.wav", filename, sid); } } fprintf(stderr,"[%s]", outpath); if (access(outpath, F_OK) == 0) { if (access(outpath, W_OK) == 0) { fprintf(stderr, "(override)"); } else { perror("adintool"); return(-1); } } if (use_raw) { if ((fd = open(outpath, O_CREAT | O_RDWR #ifdef O_BINARY | O_BINARY #endif , 0644)) == -1) { perror("adintool"); return -1; } } else { if ((fp = wrwav_open(outpath, sfreq)) == NULL) { perror("adintool"); return -1; } } writing_file = TRUE; } /* write recorded sample to file */ if (use_raw) { count = wrsamp(fd, &(now[start]), len); if (count < 0) { perror("adinrec: cannot write"); return -1; } if (count < len * sizeof(SP16)) { fprintf(stderr, "adinrec: cannot write more %d bytes\ncurrent length = %d\n", count, speechlen * sizeof(SP16)); return -1; } } else { if (wrwav_data(fp, &(now[start]), len) == FALSE) { fprintf(stderr, "adinrec: cannot write\n"); return -1; } } /* accumulate sample num of this segment */ speechlen += len; /* if input length reaches limit, rehash the ad-in buffer */ if (recog->jconf->input.speech_input == SP_MIC) { if (speechlen > MAXSPEECHLEN - 16000) { recog->adin->rehash = TRUE; } } /* progress bar in dots */ fprintf(stderr, "."); return(0); }