Пример #1
0
/**
 * <EN>
 * @brief  Read samples from device (required)
 *
 * This function is for reading samples to be recognized from input stream.
 * This will be called repeatedly at each time the read samples are fully
 * processed.
 *
 * The sampling format should be 16bit, 1 channel.
 *
 * @a sampnum is the maximum number of samples that can be read into @a buf.
 * The actual number of read samples should be returned.
 *
 * Impotant notes about I/O blocking:
 *  - Do not wait until all the @a sampnum samples are read.
 *    Blocking inside this function will block the whole recognition process.
 *    If device allows, it is better to read only the available data
 *    in the stream and return immediately.
 *  - Avoid returning value of 0 when no data is available, wait for some
 *    data to come inside this function.  When you are using non-blocking
 *    operation, you may want to return 0 when no data is available.
 *    However, returning 0 will cause Julius to call again this function
 *    immediately, and cause busy loop to make CPU load to reach 100%.
 *
 * So the ideal operation will be first wait_for_some_data_to_come, and
 * if any data becomes available, read them at most @a sampnum samples
 * and return the number of read samples.
 *
 * Positive return value should be the number of read samples, or one
 * of ADIN_EOF, ADIN_SEGMENT or ADIN_ERROR.  Return value of ADIN_EOF
 * tells end of stream, which causes Julius to finish current
 * recognition and close stream.  ADIN_SEGMENT requests Julius to
 * segment the current input.  The current recognition will be stopped
 * at this point, recognition result will be output, and then Julius
 * continues to the next input.  The behavior of ADIN_SEGMENT is
 * similar to ADIN_EOF except that ADIN_SEGMENT does not close/open
 * stream, but just stop and restart the recognition.  At last, return
 * value should be ADIN_ERROR on error, in which Julius exits itself
 * immediately.
 *
 * @param buf [out] output buffer to store samples obtained.
 * @param sampnum [in] maximum number of samples that can be stored in @a buf.
 *
 * @return actural number of read samples, ADIN_EOF on end of stream,
 * ADIN_SEGMENT to request segmentation to Julius, or ADIN_ERROR on error.
 * </EN>
 * <JA>
 * @brief  デバイスからサンプルを読み込む(必須)
 *
 * この関数は入力ストリームから音声サンプルを読み込む.
 *
 * バッファに格納して返す音声データの形式は 16bit, 1 チャンネルであること.
 *
 * @a sampnum は @a buf に格納することのできる最大のサンプル数である.
 * 返り値として,実際に読み込まれたサンプル数,あるいは以下で説明する
 * エラーコードを返す.
 *
 * この関数は認識中に何度も呼ばれ,ここで読まれたデータが Julius によっ
 * て 認識処理される.読み込んだ分の処理が終了すると,次の入力を読み込
 * むためにこの関数が再度呼ばれる.
 *
 * この関数内での I/O blocking については以下の注意が必要である:
 *
 *  - 長時間のブロックは避けること(@a sampnum は要求サンプル数ではな
 *  く@a buf に格納可能な最大数である).この関数内でブロックすると認
 *  識処理全体がブロックする.読み込みが長時間ブロックしないよう,数百
 *  サンプル程度だけ読み込んで返すか,あるいは最初にバッファ内にあるブ
 *  ロックせずに読み込み可能なデータサンプル数を取得し,その分だけ読み
 *  込むようにするのがよい.
 *
 *  - non-blocking モードを用いる場合, 0 を返さないこと.
 *    バッファにデータが存在しないとき,0 を返すと Julius はサンプル
 *    無しのためまた即座にこの関数を呼び出す.これがビジーウェイトを
 *    発生させ,CPUロードがあがってしまう.バッファにデータが無いとき,
 *    即座に 0 を返さず,数十msec でよいのでこの関数内で待つ
 *    ことが望ましい.
 *
 * 返り値は,実際に読み込んだサンプル数を正の値として返すか,あるいは
 * ADIN_EOF, ADIN_SEGMENT, ADIN_ERROR のどれかを返す.ADIN_EOF はスト
 * リームが終端まで達したことを表す,これを返すと,Julius は現在の認識
 * 処理を終了させ,ストリームを閉じる.ADIN_ERROR はこの関数内で深刻な
 * エラーが生じた場合に返す.これが返された場合,Julius はその場で異常
 * 終了する.
 *
 * ADIN_SEGMENT を返すことで,Julius に現在の認識を現時点で区切ること
 * を要求することができる.現在の認識処理はこの時点でいったん区切られ,
 * そこまでの認識結果が確定・出力されたあと,次の認識処理が始まりこの
 * 関数が呼ばれる.ADIN_SEGMENT は ADIN_EOF と動作が似ているが,
 * ADIN_EOF が adin_close(), adin_open() を呼んでストリームを終了させ
 * るのに対して,ADIN_SEGMENT はこれらを呼ばずに入力を続行する.この機
 * 能は,たとえばネットワーク経由で音声データを受信しているときに,送
 * 信側から音声認識のON/OFFやVADをコントロールしたい場合などに
 * 使うことができる.
 *
 * @param buf [out] 得られたサンプルを格納するバッファ
 * @param sampnum [in] @a buf 内に格納できる最大サンプル数
 *
 * @return 実際に読み込まれたサンプル数,あるいは end of stream 時に ADIN_EOF,
 * Julius に区切り要求を出すときには ADIN_SEGMENT, エラー時はADIN_ERROR を
 * 返す.
 * </JA>
 */
int
adin_read(SP16 *buf, int sampnum)
{
    int size, cnt;
    static int i=0;


    size = getFileSize(sock);
    if(size == -1) {
        fprintf(stderr, "getFileSize failed. Invalid file size\n");
    }
    else {
        DEBUG_PRINT(".", size);
    }
    cnt = size / sizeof(SP16);
    getSoundFile(sock, size, fp, buf);
    //swap_sample_bytes(buf,cnt);

    if(i++>10) {
        i=0;
        return ADIN_SEGMENT;
    }

    return(cnt);

}
Пример #2
0
int main(void){
	// socket
	int sock;
	// file size
	int fileSize = 0;
	// file pointer
	FILE* fp;

	//counter
	int count = 0;

	// open the file
	fp = fopen("rec.raw", "wb" );
	if( fp == NULL ){
		fputs( "ERROR: File\n", stderr );
		exit( EXIT_FAILURE );
	}

	// connect client	
	sock = getConnect(12345);
	printf("connected\n");

	while(count < 100){
		// get file size
		fileSize = getFileSize(sock);
		if(fileSize == -1){
			printf("ERROR\n");
			break;
		}
		else{
			printf("file size: %d\n", fileSize);
		}

		// get sound data
		if(getSoundFile(sock, fileSize, fp) == -1){
			break;
		}
		count++;
	}

	
	//file close
	fclose(fp);
	// close socket
	close(sock);
	return 0;
}
Пример #3
0
int main() {
  mu::SequenceSP sequence_sp;
  mu::LoopSP loop_sp;
  mu::RtPlayer player;

  sequence_sp.addSource(getSoundFile(SOUND_DIR "E4" ".wav"), 0.0*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "C5" ".wav"), 1.0*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "B4" ".wav"), 1.5*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "G4" ".wav"), 2.5*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "E4" ".wav"), 3.5*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "E4" ".wav"), 4.5*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "D4" ".wav"), 5.5*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "G4" ".wav"), 6.0*Q);
  sequence_sp.addSource(getSoundFile(SOUND_DIR "E4" ".wav"), 6.5*Q);

  loop_sp.setSource(&sequence_sp).setLoopDuration(sequence_sp.getEnd());
  player.setSource(&loop_sp);
  player.start();
  sleep(30);
  player.stop();

  return 0;
}
Пример #4
0
	std::string getSoundFile(const char *name) const {
		return getSoundFile(lif::sid(name));
	}