Menu

PocketSphinx runtime JSGFswitch

Help
Paul
2010-06-10
2012-09-22
  • Paul

    Paul - 2010-06-10

    Hi,

    I've got PocketSphinx up and running, and all is working great.

    I'm generating a new JSGF grammar at runtime in code for each user
    interaction. Is there a nice way to switch my existing ps_decoder_t to use the
    newly generated JSGF grammar please?

    For reference, I've got the following working, but it reloads the acoustic
    model, dictionary, etc. and so is pretty slow:

    g_argv = pNewGrammarFilename;
    cmd_ln_t *config = cmd_ln_parse_r( NULL, cont_args_def, argc, g_argv, FALSE );
    ps_reinit(ps, config);

    Thanks for your help,
    Paul

     
  • Nickolay V. Shmyrev

    To change the grammar you need to use ps_get_fsgset/ps_update_fsgset API. To
    get fsgset from jsgf you can use jsgf_parse_file/jsgf_build_fsg

     
  • Nickolay V. Shmyrev

    And, its probably way more easier for you to build fsg instead of jsgf
    directly

     
  • Paul

    Paul - 2010-06-18

    Thanks for your help, that worked a treat. I did have to add another call to
    pocketsphinx.h to get the acoustic model: POCKETSPHINX_EXPORT
    acmod_t ps_get_acmod(ps_decoder_t ps);

    Here's the code, in case anyone else wants to do this:

    jsgf_t pJSGF = jsgf_parse_file( pGrammarFilename, NULL );
    if( pJSGF )
    {
    jsgf_rule_iter_t
    itor;
    jsgf_rule_t *rule = NULL;

    for (itor = jsgf_rule_iter(pJSGF); itor; itor = jsgf_rule_iter_next(itor))
    {
    rule = jsgf_rule_iter_rule(itor);

    if (jsgf_rule_public(rule)) break;
    }

    fsg_model_t pNewFSGModel = jsgf_build_fsg( pJSGF, rule,
    ps_get_acmod(ps)->lmath, 6.5);
    if( pNewFSGModel )
    {
    fsg_set_t
    pCurrentGrammar = ps_get_fsgset( ps );
    pCurrentGrammar->fsg = pNewFSGModel;
    ps_update_fsgset(ps);
    }
    }

    Cheers,
    Paul

     
  • Nickolay V. Shmyrev

    Actually to get logmath from ps, it's better to use
    ps_get_logmath(ps_decoder_t *ps) instead of ps_get_acmod->lmath.

     
  • Paul

    Paul - 2010-06-23

    Thanks

     
  • Anonymous

    Anonymous - 2012-01-05

    Sorry to bring this old thread up again. But I have a problem using the code
    of lemmin.

    The line:

    pCurrentGrammar->fsg = pNewFSGModel;

    brings up a compile error:
    "Building file: ../fsg_example.c
    Invoking: GCC C Compiler
    gcc -I/usr/include/sphinxbase -I/usr/include/pocketsphinx -O0 -g3 -Wall -c
    -fmessage-length=0 -MMD -MP -MF"fsg_example.d" -MT"fsg_example.d" -o
    "fsg_example.o" "../fsg_example.c"
    ../fsg_example.c: In function ‘main’:
    ../fsg_example.c:48:19: error: dereferencing pointer to incomplete type
    make: *** Error 1"

    I installed sphinxbase and pocketshinx using the fedora package manager. Both
    are version 0.7. Same thing happens for a friend of mine on arch linux.

    Has the api changed somehow?

     
  • Nickolay V. Shmyrev

    Has the api changed somehow?

    Yes, you need to use fsg_set_add / fsg_set_select to add fsg_model_t to
    fsg_set_t in runtime. You can find an example in pocketsphinx sources.

     

Log in to post a comment.