Menu

Pocketsphinx dynamic grammar

Help
2011-10-20
2012-09-22
  • Mattia Ferrari

    Mattia Ferrari - 2011-10-20

    Hello,
    I tried to add a way to dynamically modify the grammar in pocketsphinx (I'm
    using the latest revision of ps and sphinxbase). I made the function
    ps_set_fsg_from_rule_list which can be called between one utterance and
    another to change the grammar. It takes a list of rule names (of the jsgf) and
    should replace the current fsg set with another made with these rules.

    <<pocketsphinx.c>>
    
    void ps_set_fsg_from_rule_list( ps_decoder_t *decoder, glist_t ruleNames ) {
        fsg_search_t *fsgs;
        jsgf_rule_t *mainRule;
        fsg_model_t *newModel, *oldModel;
    
        fsgs = (fsg_search_t *)decoder->search;
    
        mainRule = jsgf_set_from_rule_list( fsgs->jsgf, ruleNames );
    
        newModel = jsgf_build_fsg( fsgs->jsgf, mainRule, decoder->acmod->lmath, (float32)fsgs->lw );
        oldModel = fsg_set_remove( fsgs, fsgs->fsg );
        if ( oldModel ) {
            fsg_model_free( oldModel );
        }
        fsg_set_add( fsgs, fsg_model_name( newModel ), newModel );
        fsg_set_select( fsgs, fsg_model_name( newModel ) );
        fsg_search_reinit( ps_search_base( fsgs ), ps_search_dict( fsgs ), ps_search_dict2pid( fsgs ) );
        ps_update_fsgset( decoder );
    }
    

    The jsgf_set_from_rule_list function sets the new jsgf grammar and returns the
    root rule. Can you please tell me if you think the above function cleans and
    sets the new grammar properly? From what i've tested so far it seems to work,
    though.

    Thanks for your attention.

     
  • Nickolay V. Shmyrev

    Can you please tell me if you think the above function cleans and sets the
    new grammar properly?

    This function accesses the pocketsphinx internals, it's not recommended to do
    that. For example to get fsg set you need to use the function ps_get_fsgset.

     
  • Mattia Ferrari

    Mattia Ferrari - 2011-10-21

    Thanks for the advice.
    So I assume the function calls to remove the old fsg and set the new one make
    sense.

     

Log in to post a comment.