Here's how it works:
Pocketsphinx actually keeps track of a set of grammars at all time. Normally, this set of grammars only has one element. However, it can contain multiple grammars, while only one is switched on at a time. The basic method is
- get this set of grammars using ps_get_fsgset()
- Add your grammar to the set using fsg_set_add()
- Select your grammar from the set as the active one using fsg_set_select()
- Notify the recognizer that you have updated the grammar using ps_update_fsgset()
ps_decoder_t * p= ...; //Decoder already initialized somehow
fsg_model_t * m= ...; //Load the model using fsg_model_read or jsgf_parse_file and jsgf_build_fsg
fsg_set_add(fsgset, "newgrammarname", m);
NOTE: I realize that even jsgf_build_fsg is confusing. Here's how you should handle it:
jsgf_build_fsg(jsfgmodel, rule, ps_get_logmath(ps), 6.5);
where jsfgmodel is the jsgf model loaded using jsgf_parse_file, and "rule" is a rule chose from it. (use the jsgf_* functions to select the rule). Also, free the jsgf once the fsg has been created using jsgf_grammar_free.
Oh yeah, and the 6.5 just seems to be a magic number. In two places I've seen it used without any explanation. The documentation says nothing about what the number "lw" does anywhere, so I'd just stick to the value 6.5 and hope for the best...