为什么pocketphinx的代码列表在我的ubuntu中不起作用?

时间:2016-09-16 16:46:06

标签: c ubuntu speech-recognition pocketsphinx

我根据此link.安装了pocketsphinx。在本教程中,有一个列表代码。 代码是:

#include <pocketsphinx.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;

    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",
                 NULL);
    if (config == NULL) {
        fprintf(stderr, "Failed to create config object, see log for details\n");
        return -1;
    }

    ps = ps_init(config);
    if (ps == NULL) {
        fprintf(stderr, "Failed to create recognizer, see log for details\n");
        return -1;
    }

    fh = fopen("goforward.raw", "rb");
    if (fh == NULL) {
        fprintf(stderr, "Unable to open input file goforward.raw\n");
        return -1;
    }

    rv = ps_start_utt(ps);

    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);
    hyp = ps_get_hyp(ps, &score);
    printf("Recognized: %s\n", hyp);

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

    return 0;
}

在本教程中,有一条关于MODELDIR的内容是:

  

通过使用,在GCC命令行上定义了MODELDIR宏   pkg-config从PocketSphinx获取modeldir变量   配置。

在这段代码中,运行此命令得到的modeldir变量

 abnormal@abnormal:~$ pkg-config --variable=modeldir pocketsphinx
/usr/local/share/pocketsphinx/model

所以我按照以下方式编辑了代码:

#include <pocketsphinx.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;

    config = cmd_ln_init(NULL, ps_args(), TRUE,
                         "-hmm",  "/usr/local/share/pocketsphinx/model/en-us/en-us",
                         "-lm",  "/usr/local/share/pocketsphinx/model/en-us/en-us.lm.bin",
                         "-dict", "/usr/local/share/pocketsphinx/model/en-us/cmudict-en-us.dict",
                         NULL);
    if (config == NULL)
    {
        fprintf(stderr, "Failed to create config object, see log for details\n");
        return -1;
    }

    ps = ps_init(config);
    if (ps == NULL)
    {
        fprintf(stderr, "Failed to create recognizer, see log for details\n");
        return -1;
    }

    fh = fopen("goforward.raw", "rb");
    if (fh == NULL)
    {
        fprintf(stderr, "Unable to open input file goforward.raw\n");
        return -1;
    }

    rv = ps_start_utt(ps);

    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);
    hyp = ps_get_hyp(ps, &score);
    printf("Recognized: %s\n", hyp);

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

    return 0;
}

然后我编译并运行代码。但我得到了错误:

abnormal@abnormal:~$ cd Desktop
abnormal@abnormal:~/Desktop$ gcc -c Untitled1.c -o sss.o `pkg-config --cflags --libs pocketsphinx sphinxbase`
abnormal@abnormal:~/Desktop$ ./sss.o
bash: ./sss.o: Permission denied

我做错了什么?我现在做什么sholud?我使用的是ubuntu 14,04 LTS。请帮忙。

0 个答案:

没有答案