Menu

How to get time info of transcript with PS?

Help
Pang Lei
2012-09-01
2012-09-22
  • Pang Lei

    Pang Lei - 2012-09-01

    Hi, I want to use PocketSphinx to caption videos. Currently, I could generate
    transcript with the following code based on PocketSphinx 0.7.

    #include <pocketsphinx.h>
    #include <stdio.h>
    
    int
    main(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;
        char audiofile[100];
    
        int i;
    
        sprintf(audiofile, "second.wav");
    
        /*config = cmd_ln_init(NULL, ps_args(), TRUE,
                             "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
                             "-lm", "TAR3837/3837.lm",
                             "-dict", "TAR3837/3837.dic",
                             NULL);*/
        config = cmd_ln_init(NULL, ps_args(), TRUE,
                    "-hmm", "TAR3837/hub4_6000",
                    "-lm", "TAR3837/bn99_64000_lm.dmp",
                    "-dict", "TAR3837/cmudict.06d",
                    NULL);
        //This model could not be loaded
        /*config = cmd_ln_init(NULL, ps_args(), TRUE,
                    "-hmm", "/media/New Volume/Sphinx_Modes/en_broadcastnews_16k_ptm256_5000",
                    "-lm", "TAR3837/bn99_64000_lm.arpa",
                    "-dict", "TAR3837/cmudict.06d",
                    NULL);*/
        if (config == NULL)
            return 1;
    
        ps = ps_init(config);
        if (ps == NULL)
            return 1;
    
    
        fh = fopen(audiofile, "rb");
        if (fh == NULL) {
            perror("Failed to open audio file");
            return 1;
        }
    
        rv = ps_decode_raw(ps, fh, NULL, -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, NULL);
        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);*/
        ps_free(ps);
    
        return 0;
    }
    

    However, I couldn't get the time information for each word. So, could anyone
    tell me how can I get the time info? In addition, Could PocketSphinx split the
    long text into sentence?

     
  • Nickolay V. Shmyrev

    Read pocketsphinx_continuous source in pocketsphinx/src/programs/continuous.c
    for details.

     

Log in to post a comment.