Esempio n. 1
0
static int batch_decoder_decode_mfc(batch_decoder_t *bd, FILE *infh, int sf,
        int ef, alignment_t *al)
{
    featbuf_t *fb = search_factory_featbuf(bd->sf);
    mfcc_t **mfcs;
    int nfr, rv;

    if (NULL == (mfcs = read_mfc_file(infh, sf, ef, &nfr,
            cmd_ln_int32_r(bd->config, "-ceplen"))))
        return -1;

    rv = featbuf_producer_process_cep(fb, mfcs, nfr, TRUE);
    ckd_free_2d(mfcs);
    return rv;
}
Esempio n. 2
0
static int
process_ctl_line(ps_decoder_t *ps, cmd_ln_t *config,
                 char const *file, char const *uttid, int32 sf, int32 ef)
{
    FILE *infh;
    char const *cepdir, *cepext;
    char *infile;

    if (ef != -1 && ef < sf) {
        E_ERROR("End frame %d is < start frame %d\n", ef, sf);
        return -1;
    }
    
    cepdir = cmd_ln_str_r(config, "-cepdir");
    cepext = cmd_ln_str_r(config, "-cepext");

    /* Build input filename. */
    infile = string_join(cepdir ? cepdir : "",
                         "/", file,
                         cepext ? cepext : "", NULL);
    if (uttid == NULL) uttid = file;

    if ((infh = fopen(infile, "rb")) == NULL) {
        E_ERROR_SYSTEM("Failed to open %s", infile);
        ckd_free(infile);
        return -1;
    }
    /* Build output directories. */
    if (cmd_ln_boolean_r(config, "-build_outdirs"))
        build_outdirs(config, uttid);

    if (cmd_ln_boolean_r(config, "-senin")) {
        /* start and end frames not supported. */
        ps_decode_senscr(ps, infh, uttid);
    }
    else if (cmd_ln_boolean_r(config, "-adcin")) {
        
        if (ef != -1) {
            ef = (int32)((ef - sf)
                         * (cmd_ln_float32_r(config, "-samprate")
                            / cmd_ln_int32_r(config, "-frate"))
                         + (cmd_ln_float32_r(config, "-samprate")
                            * cmd_ln_float32_r(config, "-wlen")));
        }
        sf = (int32)(sf
                     * (cmd_ln_float32_r(config, "-samprate")
                        / cmd_ln_int32_r(config, "-frate")));
        fseek(infh, cmd_ln_int32_r(config, "-adchdr") + sf * sizeof(int16), SEEK_SET);
        ps_decode_raw(ps, infh, uttid, ef);
    }
    else {
        mfcc_t **mfcs;
        int nfr;

        if (NULL == (mfcs = read_mfc_file(infh, sf, ef, &nfr,
                                          cmd_ln_int32_r(config, "-ceplen")))) {
            E_ERROR("Failed to read MFCC from the file '%s'\n", infile);
            fclose(infh);
            ckd_free(infile);
            return -1;
        }
        ps_start_utt(ps, uttid);
        ps_process_cep(ps, mfcs, nfr, FALSE, TRUE);
        ps_end_utt(ps);
        ckd_free_2d(mfcs);
    }
    fclose(infh);
    ckd_free(infile);
    return 0;
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
    cmd_ln_t *config;
    ps_decoder_t *ps;

    int32 out_score;

    const char *input_file_path;
    const char *cfg;
    const char *utt_id;
    const char *hyp;
    FILE *input_file;
    int16 buf[PCM_BUF_LEN];
    int k;

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

    /* Handle argument file as -argfile. */
    if (config && (cfg = cmd_ln_str_r(config, "-argfile")) != NULL) {
        config = cmd_ln_parse_file_r(config, cont_args_def, cfg, FALSE);
    }
    if (config == NULL)
        return 1;

    if (cmd_ln_str_r(config, "-kws") == NULL && cmd_ln_str_r(config, "-keyphrase") == NULL) {
        E_ERROR("Keyword is missing. Use -keyphrase <keyphrase> or -kws <kws_file> to specify the phrase to look for.");
        return 1;
    }

    input_file_path = cmd_ln_str_r(config, "-infile");
    if (input_file_path == NULL) {
        E_ERROR("Input file is missing. Use -infile <input_file> to specify the file to look in.\n");
        return 1;
    }

    ps_default_search_args(config);
    ps = ps_init(config);
    
    if (ps == NULL) {
        E_ERROR("Failed to create the decoder\n");
        return 1;
    }
    
    input_file = fopen(input_file_path, "rb");
    if (input_file == NULL) {
        E_FATAL_SYSTEM("Failed to open input file '%s'", input_file_path);
    }
    
    ps_start_utt(ps, NULL);
    if (cmd_ln_boolean_r(config, "-adcin")) {
        fread(buf, 1, 44, input_file);
        while ((k = fread(buf, sizeof(int16), PCM_BUF_LEN, input_file)) > 0) {
            ps_process_raw(ps, buf, k, FALSE, FALSE);
        }
    } else {
        mfcc_t **mfcs;
        int nfr;

        if (NULL == (mfcs = read_mfc_file(input_file, &nfr, cmd_ln_int32_r(config, "-ceplen")))) {
            E_ERROR("Failed to read MFCC from the file '%s'\n", input_file_path);
            fclose(input_file);
            return -1;
        }
        ps_process_cep(ps, mfcs, nfr, FALSE, TRUE);
        ckd_free_2d(mfcs);
    }
    ps_end_utt(ps);

    hyp = ps_get_hyp(ps, &out_score, &utt_id);
    printf("hypothesis: %s\n", hyp);
    fflush(stdout);

    fclose(input_file);
    ps_free(ps);
    cmd_ln_free_r(config);

    return 0;
}