Menu

Usage of NBest API

Help
tfpeach
2016-01-20
2016-01-20
  • tfpeach

    tfpeach - 2016-01-20

    Hi, I found the functions in the API related to NBest list in the pocketsphinx.h as below:
    /
    * Get an iterator over the best hypotheses, optionally within a
    * selected region of the utterance. Iterator is empty now, it must
    * be advanced with ps_nbest_next first. The function may also
    * return a NULL which means that there is no hypothesis available for this
    * utterance.
    *
    * @param ps Decoder.
    * @param sf Start frame for N-best search (0 for whole utterance)
    * @param ef End frame for N-best search (-1 for whole utterance)
    * @param ctx1 First word of trigram context (NULL for whole utterance)
    * @param ctx2 First word of trigram context (NULL for whole utterance)
    * @return Iterator over N-best hypotheses or NULL if no hypothesis is available
    /
    POCKETSPHINX_EXPORT
    ps_nbest_t
    ps_nbest(ps_decoder_t ps, int sf, int ef,char const ctx1, char const *ctx2);

    There are also some functions else related to the NBest information. I did not find examples about how to use them. I want to print out the N-Best list (also the score) for each frame in the utterance. Could any one give me an example about using it?

    Thank you very much!

     
  • Nickolay V. Shmyrev

    pocketsphinx/test/unit/test_ps_nbest.c:

    for (n = 1, nbest = ps_nbest(ps); nbest && n < 10; nbest = ps_nbest_next(nbest), n++) {
            ps_seg_t *seg;
            hyp = ps_nbest_hyp(nbest, &score);
            printf("NBEST %d: %s (%d)\n", n, hyp, score);
            for (seg = ps_nbest_seg(nbest); seg;
                 seg = ps_seg_next(seg)) {
                    char const *word;
                    int sf, ef;
    
                    word = ps_seg_word(seg);
                    ps_seg_frames(seg, &sf, &ef);
                    printf("%s %d %d\n", word, sf, ef);
            }
    }
    if (nbest)
        ps_nbest_free(nbest);
    
     
    • tfpeach

      tfpeach - 2016-01-20

      Thank you! I see it.

      However, I found it also contains the code:
      TEST_ASSERT(config =
      cmd_ln_init(NULL, ps_args(), TRUE,
      "-hmm", MODELDIR "/en-us/en-us",
      "-lm", MODELDIR "/en-us/en-us.lm.bin",
      "-dict", MODELDIR "/en-us/cmudict-en-us.dict",
      "-fwdtree", "yes",
      "-fwdflat", "yes",
      "-bestpath", "yes",
      "-input_endian", "little",
      "-samprate", "16000", NULL));
      TEST_ASSERT(ps = ps_init(config));
      TEST_ASSERT(rawfh = fopen(DATADIR "/goforward.raw", "rb"));
      ps_decode_raw(ps, rawfh, -1);

      It seems it has already been configured (including the input file). If I want to use my own configuration, I have to change the part of "config". If I don't mistake, I can use:
      config = cmd_ln_parse_r(NULL, ps_args_def, argc, argv, TRUE);

      Then I can pass the parameters from the command line.

      Is this correct?

      Thank you once again.

       
      • Nickolay V. Shmyrev

        I can use:

        config = cmd_ln_parse_r(NULL, ps_args_def, argc, argv, TRUE);
        

        Yes

         

Log in to post a comment.