#include <pocketsphinx.h>
intmain(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en/turtle.DMP", "-dict", MODELDIR "/lm/en/turtle.dic", NULL);
if (config == NULL) return 1;
ps = ps_init(config);
if (ps == NULL) return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL) { perror("Failed to open goforward.raw"); return 1; }
rv = ps_decode_raw(ps, fh, "goforward", -1);
if (rv < 0) return 1;
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL) return 1;
printf("Recognized: %s\n", hyp);
fseek(fh, 0, SEEK_SET);
rv = ps_start_utt(ps, "goforward");
if (rv < 0) return 1;
while (!feof(fh)) { size_t nsamp; nsamp = fread(buf, 2, 512, fh); rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE); }
rv = ps_end_utt(ps);
if (rv < 0) return 1;
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL) return 1;
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
return 0;
}
/*note:USE the Makefile that i have writen before to compile goforward.raw in the path "pocketsphinx/test/data" */
Goto the site:http://www.speech.cs.cmu.edu/SLM/toolkit_documentation.html for how to use the toolkit
http://www.speech.cs.cmu.edu/SLM/toolkit.html to download the toolkit
After uncompress the tar-file :
editing src/Makefile directly, so that the line
#BYTESWAP_FLAG = -DSLM_SWAP_BYTESis changed to
BYTESWAP_FLAG = -DSLM_SWAP_BYTES
THEN
make install
sudo cp CMU-Cam_Toolkit_v2/bin/* /usr/bin
then you can run tools below
text2wfreq
wfreq2vocab
text2wngram
text2idngram
ngram2mgram
wngram2idngram
idngram2stats
mergeidngram
idngram2lm
binlm2arpa
evallm
interpolate
The simplest way to build a language model is to use the on-line web tool at http://www.speech.cs.cmu.edu/tools/lmtool.html. Simply click on the “Browse…” button, select the corpus.txt file you created, then click “COMPILE KNOWLEDGE BASE”.
The cprpus.txt is bellow
******NOT IN IT JUST A FLAG*********
open browser
new e-mail
forward
backward
next window
last window
open music player
**************END FLAG**************
You should see a page with some status messages, followed by a page entitled “Sphinx knowledge base”. This page will contain links entitled “Dictionary” and “Language Model”. Download these files and make a note of their names (they should consist of a 4-digit number followed by the extensions .dic and .lm). You can now test your newly created language model with PocketSphinx.
THE LAST SETP:(we assume after uncompress there is a .dic and .lm files called 8521.lm and 8521.dic)
pocketsphinx_continuous -lm 8521.lm -dict 8521.dic
Then SHOUT AT THE MICPHONE :open music player ,the tty will output :open music player