I am trying to pass pocketsphinx's recognized hyp to espeak TTS engine by this simple code:
#include<stdio.h>#include<string.h>#include<assert.h>#include<sphinxbase/err.h>#include<sphinxbase/ad.h>#include"pocketsphinx.h"#include<espeak/speak_lib.h>#include<string>#include<iostream>staticps_decoder_t*ps;staticcmd_ln_t*config;staticFILE*rawfd;ad_rec_t*ad;staticvoidrecognize_from_microphone(){int16adbuf[2048];uint8utt_started,in_speech;int32k;char*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){ps_end_utt(ps);hyp=(char*)ps_get_hyp(ps,NULL);if(hyp!=NULL){std::stringanswerr=std::string("espeak '")+hyp+"'";system(answerr.c_str());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");}}//forad_close(ad);}intmain(intargc,char*argv[]){config=cmd_ln_init(NULL,ps_args(),TRUE,"-hmm",MODELDIR"/en-us/en-us","-lm",MODELDIR"/en-us/en-us.lm.bin","-dict",MODELDIR"/en-us/cmudict-en-us.dict",NULL);ps=ps_init(config);recognize_from_microphone();ps_free(ps);cmd_ln_free_r(config);return0;}
You can compile and test this code by this command:~~~
But you can see there is a problem! The program says and repeats only the first recognized word/sentence, and can not continue recognizing and saying new words/sentences and stick in a infinite loop!
Can anyone solve this problem? I tried many ways in weeks but couldn't!
Last edit: rezaee 2018-05-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, posting many question on the same subject is not really productive. It is hard to track your progress and it is very unlikely you'll get any meaningful response. Try to update a single thread.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for that! I edited my question and tried to write the code more simple.
May you test this code and try to solve the problem with ad_stop_rec(ad); or any other solutions you may know?
I tried a lot but couldn't al all!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to pass
pocketsphinx
's recognizedhyp
toespeak
TTS engine by this simple code:You can compile and test this code by this command:~~~
g++ -std=c++11 -o myapp source.cpp
pkg-config --cflags gtk+-3.0
pkg-config --libs gtk+-3.0
-lespeak -DMODELDIR=\"pkg-config --variable=modeldir pocketsphinx
\"pkg-config --cflags --libs pocketsphinx sphinxbase
~~~
But you can see there is a problem! The program says and repeats only the first recognized word/sentence, and can not continue recognizing and saying new words/sentences and stick in a infinite loop!
Can anyone solve this problem? I tried many ways in weeks but couldn't!
Last edit: rezaee 2018-05-14
Sorry, posting many question on the same subject is not really productive. It is hard to track your progress and it is very unlikely you'll get any meaningful response. Try to update a single thread.
Sorry for that! I edited my question and tried to write the code more simple.
May you test this code and try to solve the problem with
ad_stop_rec(ad);
or any other solutions you may know?I tried a lot but couldn't al all!