intmain(intargc,char*argv[]){intfd,nread;chars[100];fd=atoi(argv[1]);printf("Lecturadedescriptor:%d\n",fd); switch(nread = read(fd,s,sizeof(s))) { case -1: perror("read"); break; case 0: perror("EOF"); break; default: printf("Leídos:%dbytes:%s\n",nread,s);}exit(EXIT_SUCCESS);}
Well, when i try to compile, qtcreator crash and i must force quit :(
Qtcreator tell me that i have more than 600 warnings and 20-30 error before
crash.
When i try to compile without pipes and fork, the program works without
warnings or errors.
Can i use pipes with pocketsphinx? if do you want, i put my 2 programs
intmain(intargc,char*argv[]){staticps_decoder_t*ps;staticcmd_ln_t*config;config=cmd_ln_init(NULL,ps_args(),TRUE,"-hmm",MODELDIR"/hmm/en_US/hub4wsj_sc_8k","-lm",MODELDIR"/lm/en/turtle.DMP","-jsgf","/home/pablo/pocket_sphinx/grammars/newgrammar.jsgf",//"-dict",MODELDIR"/lm/en/turtle.dic",NULL);ps=ps_init(config);if(ps==NULL)return1;ad_rec_t*ad;int16adbuf[4096];int32k,ts,rem;charconst*hyp;charconst*uttid;cont_ad_t*cont;charword[256];intpid,tubo[2];charfdstr[10];//charqueutilizamosparapasarlelaiddelatuberíaal//programalecturaDatos.cpppipe(tubo);switch(fork()){case(pid_t)-1://errorperror("fork");exit(EXIT_FAILURE);case(pid_t)0://hijoqueejecutaelprograma.close(tubo[1]);//elhijonovaaescribir,solovaaleer.sprintf(fdstr,"%d",pfd[0]);//convertimoslaiddelatuberia(lecturadedatos)//atipocharparapoderpasarlocomoargumento//luegoenlecturaDatos.cpplopasamosaentero.execve("./DATA.cpp","DATA",fdstr,Null);default://elpadresededicaaescribircadahypreconocidaenlatuberiadeescritura.close(tubo[0]);//tengoquecerrareltubodelecturaporqueelpadresóloescribe.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");/*Initializecontinuouslisteningmodule*/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(;;){/*Indicatelisteningfornextutterance*/printf("READY....\n");fflush(stdout);fflush(stderr);/*Waitdatafornextutterance*/while((k=cont_ad_read(cont,adbuf,4096))==0)sleep_msec(100);if(k<0)E_FATAL("Failed to read audio\n");/**Non-zeroamountofdatareceived;startrecognitionofnewutterance.*NULLargumenttouttproc_begin_utt=>automaticgenerationofutterance-id.*/if(ps_start_utt(ps,NULL)<0)E_FATAL("Failed to start utterance\n");ps_process_raw(ps,adbuf,k,FALSE,FALSE);//adbufeselbufferdndestaelarchivorawquecontieneloquequeremosdecodificar.printf("Listening...\n");fflush(stdout);/*Notetimestampforthisfirstblockofdata*/ts=cont->read_ts;/*Decodeutteranceuntilend(markedbya"long"silence,>1sec)*/for(;;){/*Readnon-silenceaudiodata,ifany,fromcontinuouslisteningmodule*/if((k=cont_ad_read(cont,adbuf,4096))<0)E_FATAL("Failed to read audio\n");if(k==0){/**Nospeechdataavailable;checkcurrenttimestampwithmostrecent*speechtoseeifmorethan1secelapsed.Ifso,endofutterance.*/if((cont->read_ts-ts)>DEFAULT_SAMPLES_PER_SEC)//samplespersec=16000break;}else{/*Newspeechdatareceived;notecurrenttimestamp*/ts=cont->read_ts;}/**Decodewhateverdatawasreadabove.*/rem=ps_process_raw(ps,adbuf,k,FALSE,FALSE);/*Ifnoworktobedone,sleepabit*/if((rem==0)&&(k==0))sleep_msec(20);}/**Utteranceended;flushanyaccumulated,unprocessedA/Ddataandstop*listeninguntilcurrentutterancecompletelydecoded*/ad_stop_rec(ad);while(ad_read(ad,adbuf,4096)>=0);cont_ad_reset(cont);printf("Stopped listening, please wait...\n");fflush(stdout);/*Finishdecoding,obtainandprintresult*/ps_end_utt(ps);hyp=ps_get_hyp(ps,NULL,&uttid);printf("Decodificacion nº %s: %s\n",uttid,hyp);fflush(stdout);/*Escribimosenlatuberialoquecontengahyp*/if(write(tubo[1],hyp,sizeof(hyp))==-1)perror("write");/*ExitifthefirstwordspokenwasGOODBYE*/if(hyp){sscanf(hyp,"%s",word);if(strcmp(word,"what")==0)break;}/*ResumeA/Drecordingfornextutterance*/if(ad_start_rec(ad)<0)E_FATAL("Failed to start recording\n");}cont_ad_close(cont);ad_close(ad);ps_free(ps);close(tubo[1]);//cierrolatuberiadeescriturareturn0;}
And DATA.cpp is upper
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What you wrote here is more or less good exept you are trying to execute CPP
file:
execve("./DATA.cpp","DATA",fdstr,Null);
Which will not work for sure. Also note that Null must be NULL. There is no
issue to use pocketsphinx with fork/execve, you just need to write your
program properly.
As for warnings, you might forgot some braces around code blocks and compiler
told you about that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I try to run the program without pocketsphinx (only fork and pipes) and run
propperly in both programs (father and son) and they can read and write good
in the pipe. but when I replace the source code of the father with all code
that you can see upper, the program crash :(
I keep looking any mistake of the braces or semicolons.
Thank you so much
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
I try to put my hyp on a pipe (father) and manage with other program (son)
with 2 sentences:
In my DATA.cpp program:
Well, when i try to compile, qtcreator crash and i must force quit :(
Qtcreator tell me that i have more than 600 warnings and 20-30 error before
crash.
When i try to compile without pipes and fork, the program works without
warnings or errors.
Can i use pipes with pocketsphinx? if do you want, i put my 2 programs
And DATA.cpp is upper
Hello.
What you wrote here is more or less good exept you are trying to execute CPP
file:
Which will not work for sure. Also note that Null must be NULL. There is no
issue to use pocketsphinx with fork/execve, you just need to write your
program properly.
As for warnings, you might forgot some braces around code blocks and compiler
told you about that.
hi!
I try to run the program without pocketsphinx (only fork and pipes) and run
propperly in both programs (father and son) and they can read and write good
in the pipe. but when I replace the source code of the father with all code
that you can see upper, the program crash :(
I keep looking any mistake of the braces or semicolons.
Thank you so much