Menu

How can i easily compile Pocketpshinx -0.7?

Help
Karro7
2011-06-16
2012-09-22
1 2 > >> (Page 1 of 2)
  • Karro7

    Karro7 - 2011-06-16

    Hi everybody, my name is atlante7. I am a beginner in computing!

    I have to compile the program pocketsphinx for an application of speech
    recognition through a robot which can understand simply orders such as "go,
    right, left, stop".

    The purpose of my studies is to eloborate this program so as the robot
    recognize these words.

    I have been studying C for one month or a little bit more. So i am a newbie!

    My teacher told me to search a program which is Free and computed with Unix.

    Therefore i chose Sphinx, especially pocketsphinx.

    Anyway, i download pocketsphinx-0.7 and sphinxbase on the site web: http://ht
    tp://cmusphinx.sourceforge.net/wiki/download/

    and install make install properly.

    For example, i can run pocketsphinx_continuous, tidigits with no problem!

    Well, you have actually noticed the fact that my english is not as good as i
    always wanted! I am a french guy!

    I have Ubuntu 10.04, and use GCC to compile and notepad or Emacs to write the
    code.

    This is my problem:

    I copy the code just on this page:
    http://cmusphinx.sourceforge.net/wiki/tuturialpocketsphinx

    Code source:

    include <pocketsphinx.h></pocketsphinx.h>

    int
    main(int argc, char argv)
    {
    ps_decoder_t
    ps;
    cmd_ln_t config;
    FILE
    fh;
    char const hyp, uttid;
    int16 buf;
    int rv;
    int32 score;

    config = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
    "-lm", MODELDIR "/lm/en/turtle.DMP",
    "-dict", MODELDIR "/lm/en/turtle.dic",
    NULL);
    if (config == NULL)
    return 1;
    ps = ps_init(config);
    if (ps == NULL)
    return 1;

    fh = fopen("goforward.raw", "rb");
    if (fh == NULL) {
    perror("Failed to open goforward.raw");
    return 1;
    }

    rv = ps_decode_raw(ps, fh, "goforward", -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, "goforward");
    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);

    fclose(fh);
    ps_free(ps);
    return 0;
    }

    But i really don't know how i can fix it!

    How can i compile this code so as to add just these things:

    -a dictionnary with four words in english ("go, stop, right, left").
    -> I already create a jsgf document or a .dic document about it.
    -a few sounds of my voice in order to say "go,stop, right left".
    -> i recorded it with the application on LINUX (the simple one) and saved as .wav

    And that's all.

    I thank you for yours answers.

    Goodbye.

     
  • Nickolay V. Shmyrev

    How can i compile this code so as to add just these things

    Do you have troubles to compile this code to a binary executable or to modify
    it to include the grammar you have.

    By compilation people usually mean the process that converts text file to a
    binary executable code. This is done by means of special tool - compile. For
    example on Linux there is gcc which compiles text

    If you want to modify the code, it's another story.

     
  • Karro7

    Karro7 - 2011-06-16

    Hi, many thanks for reply so fast!

    I want to modify the code so as to include my settings.

    And i know that some people who are computing 'better' than me told me just
    that it will be so hard for me...

    Anyway, is there a simply way to modify just a little this code so as to fix
    my settings(dictionnary 4 words, and recording 4 words)?

     
  • Nickolay V. Shmyrev

    To modify it open this file with a text editor. Go to the line

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en/turtle.DMP", "-dict", MODELDIR "/lm/en/turtle.dic", NULL);
    

    Modify it according to your needs

    config = cmd_ln_init(NULL, ps_args(), 
    TRUE, "-hmm", 
    MODELDIR "/hmm/en_US/hub4wsj_sc_8k", 
    "-jsgf", "<path_to_your_grammar_file>", 
    "-dict", "<path_to_your_dictionary_file>" NULL);
    

    Compile it and run

     
  • Karro7

    Karro7 - 2011-06-16

    Okay.

    For example, i do that:

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR
    "/hmm/en_US/hub4wsj_sc_8k", "-jsgf", "<path_to_your_grammar_file>", "-dict",
    "<path_to_your_dictionary_file>" NULL); </path_to_your_dictionary_file></path_to_your_grammar_file>

    but to indicate my path my grammar is a jsgf in Documents, so i note:
    usr/Documents/grammar1.jsgf?
    and my dictionnary has to be in the same folder than for example turtle.dic?

    So to conclude the path will be:

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR
    "/hmm/en_US/hub4wsj_sc_8k", "-jsgf", "<usr/Documents/grammar1.jsgf>",
    "-dict", "<usr/Documents/Sphinx/pocketsphinx/model/lm/en/5352.dic>" NULL);

    Is that correct?

     
  • Nickolay V. Shmyrev

    Correct is

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-jsgf", "usr/Documents/grammar1.jsgf", "-dict", "usr/Documents/Sphinx/pocketsphinx/model/lm/en/5352.dic" NULL);
    

    You just specify a file name. File name is a set of directories separated by /
    and a name of the file. Filename is enclosed in double quotes as any string in
    C

     
  • Karro7

    Karro7 - 2011-06-16

    My line:

    onfig = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
    "-jsgf","usr/Documents/Sphinx/pocketsphinx/model/en/grammar1.jsgf",
    "-dict","usr/Documents/Sphinx/pocketsphinx/model/lm/en/5353.dic" NULL);

    Good.

    I do what you told me.

    And the compiler shows me this page:

    http://www.imagup.com/data/1122892004.html

    How can i fix these ones?

     
  • Karro7

    Karro7 - 2011-06-16

    I just forgot this thing:

    I rectify the line:

    onfig = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
    "-jsgf","usr/Documents/Sphinx/pocketsphinx/model/lm/en/grammar1.jsgf",
    "-dict","usr/Documents/Sphinx/pocketsphinx/model/lm/en/5353.dic" NULL);

    (miss lm/en at line grammar1)

    And i got the same errors!

     
  • Karro7

    Karro7 - 2011-06-16

    I read for weeks this tutorial without understand how i can modify the code!

    I need help sincerely. I know i am a newbie!

    I tried to put some variables such as:

    int rv = 0;
    etc etc
    but no works.

    I am sorry, i could understand alone this code!

     
  • Karro7

    Karro7 - 2011-06-16

    I mean i could NOT understand this code alone.

    Any suggestions?

    Or Walktrhought? So as to guide me?

     
  • Karro7

    Karro7 - 2011-06-16

    Well i started to define these variables such as:

    int = 0;
    but some %s need "char".

    Ok but how could i make it?

    int ps_decoder_t ps = 0;
    int FILE
    fh = 0;
    int rv = 0;
    int ps = 0;
    int fh = 0;
    int cmd_ln_t = 0;
    int config = 0;
    int int16 = 0;
    int int32 = 0;
    int NULL = 0;
    int TRUE = 1;
    int MODELDIR= 0;
    int SEEK_SET = 0;
    int score = 0;
    int size_t = 0;
    int nsamp = 0;
    int buf = 0;
    int FALSE = 0;

    Does these variables takes int or char or anyelse? I don't know seriously

     
  • Nickolay V. Shmyrev

    Sorry, it seems you need to take some course on development using C. I
    recommend you to read this book:

    http://cm.bell-labs.com/cm/cs/cbook/

    It's certainly not an appropriate place to discuss such issues here, this is a
    forum about CMUSphinx, not about C basics.

     
  • creative64

    creative64 - 2011-06-17

    Or go through this quick on-line course. It will give you a jumpstart in 24
    hrs. It helped me.

    http://aelinik.free.fr/c/index.html

     
  • Karro7

    Karro7 - 2011-06-17

    Right. But i haven't got a lot of time! (few days)

    I need a part of this code modified than can help me to end up.

    I mean, just a few lines to define the variables and some explanations. And i
    can make it myself. Otherwise, i am totally lost.

    Does anyone got a piece of the code modifided? nshmyrev?

    Just an exemple which could inspire me!

    Thanks a lot

     
  • Nickolay V. Shmyrev

    You shouldn't modify the file except the changes I told you. You shouldn't add
    those senseless line. The variables are defined in pocketsphinx library, not
    in your code.

    To compile the source properly you need to use proper command line. Instead of

    gcc code.c -ocode
    

    You need to use

    gcc -o code code.c  -DMODELDIR=\"`pkg-config --variable=modeldir pocketsphinx`\"  `pkg-config --cflags --libs pocketsphinx sphinxbase`
    
     
  • Nickolay V. Shmyrev

    Right. But i haven't got a lot of time! (few days)

    We also don't have a lot of time to help you here.

     
  • Karro7

    Karro7 - 2011-06-17

    Ok!

    All in all, if i understand clearly, i will do what you told:

    change first line with cmd_ln_init = config ...

    and do not make any changes and just compile with the last use that you told:

    gcc -o code code.c -DMODELDIR=\"pkg-config --variable=modeldir pocketsphinx\" pkg-config --cflags --libs pocketsphinx sphinxbase

    is that correct?

     
  • Karro7

    Karro7 - 2011-06-17

    ok it gives an error: package sphinxbase was not found in the pkg config
    search path
    Perhaps you should add the directory containing sphinxbase.pc to the
    PKG_CONFIG_PATH environment variable.

    How can i fix it please?

    Do my grammar is also correct?

    grammar1.jsgf:

    JSGF V1.0;

    grammar robot;

    public <robot> = go | stop | right | left </robot>

     
  • Karro7

    Karro7 - 2011-06-17

    <"name of my code"> so Code1.c can't find a file such as Code1.c

    I make the following configurations:

    export LD_LIBRARY_PATH=/usr/local/lib
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

    ok.

    and then here the filename (Code1.c)

    and my line:

    gcc -o Code1 Code1.c -DMODELDIR=\"pkg-config --variable=modeldir pocketsphinx\" pkg-config --cflags --libs pocketsphinx sphinxbase

    error:

    nfig = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
    "-jsgf","usr/Documents/Sphinx/pocketsphinx/model/lm/en/grammar1.jsgf",
    "-dict","usr/Documents/Sphinx/pocketsphinx/model/lm/en/5353.dic" NULL);

    line C17: "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",

    error: I (first use in this function) Where is the I?

    error: 'usr' first use in this function Why? Does it effects withe the " ?

    error: 'local' first use in this function.

    error: 'include' first use in this function.

    Well there are no include no local! and could it be?

    I think it's pretty over!

    Can you help me to the finish line please?

    Many thanks!

     
  • Karro7

    Karro7 - 2011-06-17

    I tried other things.

    I saw that maybe my folders are not good indicated:

    So i do this, first to initiate:

    export LD_LIBRARY_PATH=/home/stagiaire/Documents/Sphinx/pocketsphinx/src/libpo
    cketsphinx
    export PKG_CONFIG_PATH=/home/stagiaire/Documents/Sphinx/sphinxbase-0.7/src/lib
    sphinxbase/pkgconfig

    No messages after .

    So good.

    And then i take my code and modify these lines into:

    nfig = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR
    "home/stagiaire/Documents/Sphinx/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k",
    "-jsgf", MODELDIR
    "home/stagiaire/Documents/Sphinx/pocketsphinx/model/lm/en/grammar1.jsgf",
    "-dict", MODELDIR
    "home/stagiaire/Documents/Sphinx/pocketsphinx/model/lm/en/5353.dic" NULL);

    just modified the directory.

    But i got the same errors about 'I' first time in this function (If i
    modificate MODELDIR to MODELdir = Just an error = Could not found MODELdir.

    So is my line is correct? Or MODELDIR must be with ' or " ? or ()? or
    declarate at the beginning?

    The goal is as my reach!

    Thank you for your answers.

     
  • Karro7

    Karro7 - 2011-06-17

    Well i can't understand"the finish line"!

    I do this:

    export LD_LIBRARY_PATH=/usr/local/lib export
    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

    and receives:

    -I/usr/local/include -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx
    -L/usr/local/lib -lpocketsphinx -lsphinxbase -lsphinxad

    Good one?

    And then my code:

    config = cmd_ln_init(NULL, ps_args(), TRUE,
    "-hmm", MODELDIR "<home stagiaire="" documents="" sphinx="" pocketsphinx="" model="" hmm="" en_u="" s="" hub4wsj_sc_8k="">",
    "-jsgf",
    "<home stagiaire="" documents="" sphinx="" pocketsphinx="" model="" lm="" en="" grammar1.jsgf="">",
    "-dict", "<home stagiaire="" documents="" sphinx="" pocketsphinx="" model="" lm="" en="" 5353.dic="">"
    NULL); </home></home></home>

    and the error:

    'I' undeclared (first use in this function) ("It's the I of MODELDIR!")

    'usr' undeclared (first use in this function)

    'local' undeclared (first use in this function)

    'include' undeclared (first use in this function)

    How can i fix it??

     
  • Karro7

    Karro7 - 2011-06-17

    When i define int usr =0;
    int local = 0;
    int include = 0;
    int I = 0;

    The compilator found me an error at line C.23

    config = cmd_ln_init(NULL, ps_args(), TRUE,"-hmm", MODELDIR
    "/hmm/en_US/hub4wsj_sc_8k","-jsgf",
    "home/stagiaire/Documents/Sphinx/pocketsphinx/model/lm/en

    error expected ')' before string constant.

    How can i repair it?

     
  • Karro7

    Karro7 - 2011-06-17

    Well after an hour i saw i made a mistake with -hmm which needs to be before
    MODELDIR.

    But i write this part of code:

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR
    "/hmm/en_US/hub4wsj_sc_8k",
    "-jsgf",
    "/home/stagiaire/Documents/Sphinx/pocketsphinx/model/lm/en/grammar1.jsgf",
    "-dict", "/home/stagiaire/Documents/Sphinx/pocketsphinx/model/lm/en/5353.dic"
    NULL);

    And i got the same error at this line: expect ')' before string constant.

    config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR
    "/hmm/en_US/hub4wsj_sc_8k",

    ?

     
  • Karro7

    Karro7 - 2011-06-20

    Hello i finally get it to compile the code.

    But when i ran gcc -c CodeCompSphinx.c -o CodeCompSphinx - DMODELDIR... libs
    pocketsphinx sphinxbase.

    And do:

    ./CodeCompSphinx

    It declares: Permission denied (bash).

    Why?

    I have to finish it for today!

    Thanks for reply!

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.