Menu

Help PocketSphinx with QT

Help
2018-01-23
2018-01-23
  • Miguel Lujan

    Miguel Lujan - 2018-01-23

    Hi!, maybe could be a silly question but I need help to config pocketsphinx.
    I want to create a QT programm with PocketSphinx that can control a Radar with the voice....I follow the instruccions to download the sphinxbase and pocketsphinx. I can run the pocketsphinx with the "cmd" from windows, already add the library, and everything load like in the cmd from windows, unless the last part:

    "INFO: continuous.c <307>: bin\Release\Win32\pocketsphinx_continuous.exe COMPILED ON: Jan 15 2018, AT: 14:48:08."

    That part dont appear in QT. I used the "config" that appear in the tutorial.
    Also I dont know how send the "-inmic yes". In the tutorial is on the command that call the continuous.exe, but i dont know how put the "-inmic yes" in the config, so when i call the "ps_init" works like in windows.

    I know to some could be something silly, but i dont figure out know and I hope someone can help me.

    I add pro, h and cpp file.

    pro file:
    
    win32: LIBS += -L$$PWD/sphinx/pocketsphinx/bin/Release/Win32/ -lpocketsphinx
    INCLUDEPATH += $$PWD/sphinx/pocketsphinx/bin/Release/Win32
    DEPENDPATH += $$PWD/sphinx/pocketsphinx/bin/Release/Win32
    INCLUDEPATH += $$PWD/sphinx/sphinxbase/include/
    INCLUDEPATH += $$PWD/sphinx/pocketsphinx/include/
    win32: LIBS += -lpocketsphinx
    win32: LIBS += -lsphinxbase
    
    h file:
    
    #include <QMainWindow>
    #include <pocketsphinx.h>
    #include <sphinxbase/err.h>
    #include <sphinxbase/ad.h>
    #include <QDebug>
    
    namespace Ui {
    class Speech;
    }
    
    class Speech : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit Speech(QWidget *parent = 0);
        ~Speech();
        ps_decoder_t *ps = NULL;
        cmd_ln_t *config = NULL;
    
    private slots:
        void on_Start_Button_clicked();
    
    private:
        Ui::Speech *ui;
    };
    
    #endif // SPEECH_H
    
    cpp file:
    
    Speech::Speech(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::Speech)
    {
        ui->setupUi(this);
    
        config = cmd_ln_init (NULL, ps_args(), TRUE,
                             "-hmm", MODELDIR "/en-us/en-us",                       // Acoustic Model Path
                             "-lm", MODELDIR "/en-us/en-us.lm.bin",                 // Language Model Path
                             "-dict", MODELDIR "/en-us/cmudict-en-us.dict",         // Dictionary Path
                              NULL);
    }
    
    void Speech::on_Start_Button_clicked()
    {
        ps = ps_init(config);
    
    }
    
     
    • Nickolay V. Shmyrev

      Also I dont know how send the "-inmic yes".

      -inmic is an option for pocketsphinx_continuous to switch between file and microphone. If you use pocketsphinx in your application and you do not need such switch with command line option, you do not need inmic option at all, you simply record the audio from the microphone and send it to recognizer. You can read pocketsphinx_continuous sources for details.

      https://github.com/cmusphinx/pocketsphinx/blob/master/src/programs/continuous.c#L234

       
  • Miguel Lujan

    Miguel Lujan - 2018-01-23

    Thanks for the fast answer :D

    So...correct me if I'm wrong, after I send the "ps_init", I have to "recognize_from_microphone()" using :

    (cmd_ln_str_r(config, "-adcdev"),(int) cmd_ln_float32_r(config,"-samprate"))
    

    When I make that, come this error:

    ERROR: "cmd_ln.c", line 942: Unknown argument: -adcdev

    Error that I fix like you said in:

    https://sourceforge.net/p/cmusphinx/discussion/help/thread/98d90279/?limit=25#9025

    and end the code is:

     if ((ad = ad_open_dev(NULL,(int) cmd_ln_float32_r(config,"-samprate"))) == NULL)
    

    For the moment works :D!....its not exactly the words I said, but I want to create a dictionary, to incluid just the words I want. So for that i will read about it.

    Thanks for the help!!....

    Pd: If in the future I need help with that....I hope you can help me :D

     

    Last edit: Miguel Lujan 2018-01-23
    • Nickolay V. Shmyrev

      (cmd_ln_str_r(config, "-adcdev"),(int) cmd_ln_float32_r(config,"-samprate"))

      You do not need configuration like this in your app, you can use default vaules

      For the moment works :D!....its not exactly the words I said, but I want to create a dictionary, to incluid just the words I want. So for that i will read about it.

      Ok, congratulations. You might want to move speech processing to a separate thread to avoid UI blocking.

      Pd: If in the future I need help with that....I hope you can help me :D

      Sure, feel free to ask.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.