2013-06-13 1 views
0

이제 pocketSphinx를 사용하여 C 라이브러리를 작성합니다. 문제는 모든 헤더 파일 (아래 코드처럼)과 함께 main 함수를 넣으면 잘 동작한다는 것입니다. 그럼 정적 라이브러리 (주요 기능을 포함하지 않는 코드)했다. 하지만 다른 기본 함수에서이 lib를 사용하려고하면 오류가 발생했습니다 :자체 빌드 라이브러리 사용시 오류가 발생했습니다.

/usr/local/include/sphinxbase/ad.h:106:27: FATAL error: sphinx_config.h:no such file or directory

... 컴파일 할 때. 내 헤더 파일의 경로와 관련된 문제 일 수 있다고 생각합니다.

아무도이 문제를 해결할 수있는 방법을 말해 줄 수 있습니까?

은 아래 코드는 잘 작동 :

//system headerfiles 

#include <stdio.h> 
#include <string.h> 
#include <sys/types.h> 
#include <sys/time.h> 
#include <signal.h> 
#include <setjmp.h> 

// 녹음 및 재생을위한 일반적인 라이브 오디오 인터페이스

#include <sphinxbase/ad.h> 
#include <sphinxbase/cont_ad.h> 

// pocketsphinx headerfiles

내가 언급했듯이
#include <sphinxbase/err.h>  
#include "pocketsphinx.h" 

static ps_decoder_t *ps; 
static cmd_ln_t *config; 

static void print_word_times(int32 start) 
{ 
ps_seg_t *iter = ps_seg_iter(ps, NULL); 
while (iter != NULL) 
{ 
    int32 sf, ef, pprob; 
    float conf; 

    ps_seg_frames (iter, &sf, &ef); 
    pprob = ps_seg_prob (iter, NULL, NULL, NULL); 
    conf = logmath_exp(ps_get_logmath(ps), pprob); 
    printf ("%s %f %f %f\n", ps_seg_word (iter), (sf + start)/100.0, (ef + start)/ 100.0, conf); 
    iter = ps_seg_next (iter); 
} 
} 

/* Sleep for specified msec */ 
static void sleep_msec(int32 ms) 
{ 
struct timeval tmo; 

tmo.tv_sec = 0; 
tmo.tv_usec = ms * 1000; //original was 1000 try to modify here to reduce        the sleeping time 
select(0, NULL, NULL, NULL, &tmo); 
} 



char const *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]; 

if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), 
         (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) 
    E_FATAL("Failed top 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"); 


    /* 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 (;;) { 
      /* 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); 

     printf("%s: %s\n", uttid, hyp); 

     fflush(stdout); 

     /* 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); 

return hyp; 
} 

static jmp_buf jbuf; 
static void sighandler(int signo) 
{ 
    longjmp(jbuf, 1); 
} 

int main(int argc, char *argv[]) 
{ 
char const *word; 
    config = cmd_ln_init(NULL, ps_args(), TRUE, 
"-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", 
"-lm", "/home/nieluming/Desktop/speech_lib/models/2253.lm", 
"-dict", "/home/nieluming/Desktop/speech_lib/models/2253.dic", 
NULL); 

    if (config == NULL) 
     return 1; 


    ps = ps_init(config); 
    if (ps == NULL) 
     return 1; 

    signal(SIGINT, &sighandler); 
    if (setjmp(jbuf) == 0) 
     word = recognize_from_microphone(); 

printf("%s\n", word); 

     ps_free(ps); 
    return 0; 
} 

, 위의 코드와 아래의 headfile을 lib로 만들었습니다 :

#ifndef MIC_RECOG_H 
#define MIC_RECOG_H 

char const *recognize_from_microphone(); 

#endif 

이 lib를 사용하면 "헤더 파일에 문제가 없습니다"라는 메시지가 표시됩니다.

+0

라이브러리 헤더를 어떻게 사용합니까? 라이브러리 옆에 sphinxbase 헤더가 포함되어있는 것으로 보입니다. 여러분은 그렇게하지 말아야한다. 단지 #include 을 주 응용 프로그램에 추가하기 만하면된다. #include sphinxbase.h –

답변

2

-I/usr/local/include/sphinxbase을 사용중인 컴파일러 옵션 세트에 추가하십시오.

-I <path>은 포함될 파일을 검색 할 pathes 세트에 path을 추가합니다.

+0

안녕하세요. 요점은 알았지 만, 어떻게 헤더 파일 "sphinx_config"를 찾을 수 있습니까? h "는 무엇입니까? 감사. – noben

+0

'find/-name sphinx_config.h'가 도움이 될 수 있습니다. '/ usr/local/include/sphinxbase /'에 있지 않습니까? – alk

+0

감사합니다. 헤더 파일이 있습니다. 그러나 나는 다른 문제에 직면하고 있으며, 나는 그들을 해결하려고 노력하고있다. – noben