Menu

fault adding grammar search: digits on pocketsphinx for windows phone

Help
2016-07-25
2016-08-11
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-25

    I've build my own acoustic model in Bahasa Indonesia semi-continuous for digit recognizer and I want to use it for my app in Windows Phone.
    I've included my acoustic model to hmm folder in folder Assets, dict file and lm file as well. I modified digits.gram file become like this

    #JSGF V1.0;
    
    grammar digits;
    
    <digit> = satu  |
              dua   |
              tiga   |
              empat |
              lima  |
              enam  |
              tujuh   |
              delapan |
              sembilan |
              sepuluh  |
              sebelas|
              puluh|
              belas|
              ya|
              tidak|
              ada;
    
    public <digits> = <digit>+;
    

    In this method , I got error said "fault adding grammar search : digits"

    private async Task InitialzeSpeechRecognizerForContinuous()
            {
                List<string> initResults = new List<string>();
    
                try
                {
                    AudioContainer.SphinxSpeechRecognizer = new SpeechRecognizer();
                    speechRecognizer = AudioContainer.SphinxSpeechRecognizer;
                         await Task.Run(() =>
                        {
                            var initResult = speechRecognizer.Initialize("\\Assets\\models\\hmm\\id-id", "\\Assets\\models\\dict\\an4.dic");
                            initResults.Add(initResult);
                            initResult = speechRecognizer.AddGrammarSearch(RecognizerMode.Digits.ToString(), "\\Assets\\models\\grammar\\digits.gram");
                            initResults.Add(initResult);
    
                        });
                }
                catch (Exception ex)
                {
                    var initResult = ex.Message;
                    initResults.Add(initResult);
                }
    
                foreach (var result in initResults)
                {
                    Debug.WriteLine(result);
                }
            }
    

    My question :
    1. I build my acoustic model with .lm, can I use .gram/.jsgf in pocketsphinx, instead of .lm ?
    2. Is there something wrong with my digits.gram file since the error came up from it

    Thank you

     
    • Nickolay V. Shmyrev

      1. I build my acoustic model with .lm, can I use .gram/.jsgf in pocketsphinx, instead of .lm ?

      Yes.

      1. Is there something wrong with my digits.gram file since the error came up from it

      It looks fine. You can check log output for details.

       
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-26

    Hi, thank you for the answer.

    I attach my full errors.log here and I couldn't find any information regarding the "fault adding grammar search". You may want to take a look the log. The only information that I have suspicion on became a problem is this line

    INFO: acmod.c(117): Attempting to use PTM computation module
    

    Since my model using semi-continuous, not PTM.

    My app also will crash when I tried to add Ngram search with my .DMP file.
    That makes me crazy since PocketSphinx in Linux did great. Is there some possibility there is something wrong with SpeechRecognizer.cpp made by Toine de Boer? Or there is something I miss here.

    Thank you

     
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-26

    I just did train with PTM type, but the error stil occured. I think my model is not the problem.

     
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-26

    Sorry abour the error.log . It must be incompleted. I just noticed that you've answered my question at https://sourceforge.net/p/cmusphinx/discussion/help/thread/3ace5e43/?limit=25#1291

    You said that "You can add a call of fflush(stderr) to err.c" . But, I'm sorry I don't understand where I can add fflush() in that file.

     
    • Nickolay V. Shmyrev

      In the end of err_logfp_cb function.

       
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-26
    void
    err_logfp_cb(void *user_data, err_lvl_t lvl, const char *fmt, ...)
    {
        va_list ap;
        FILE *fp = err_get_logfp();
    
        if (!fp)
            return;
    
        va_start(ap, fmt);
        vfprintf(fp, fmt, ap);
        va_end(ap);
        fflush(stderr);
    }
    

    As you mentioned, I've add a call fflush(stderr) and rebuild the project. But , the error log still same with the previous.

     
    • Nickolay V. Shmyrev

      Add fflush(fp) instead of stderr

       
  • Hamdan Prakoso

    Hamdan Prakoso - 2016-07-26

    Okay. But errors.log still same with the previous , again.

    Edit

    Is there any alternatives way to get the full error logs ?
    I got the errors.log from LocalStorage
    Here's the method in SpeechRecognizer.cpp to get the log provided in project example by Toine de Boer

    Platform::String^ SpeechRecognizer::Initialize(Platform::String^ hmmFilePath, Platform::String^ dictFilePath)
    {
        if (initializedRecognitionType != RecognitionType::None)
        {
            return "PocketSphinx is already initialized";
        }
    
        cmd_ln_t *config;
    
        // Get Local Storage Path
        wcstombs(applicationLocalStorageFolder, Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data(), 1024);
        // Get Installed Folder path
        wcstombs(applicationInstallFolderPath, Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data(), 1024);
    
        // Get Error file path (optionaly)
        char *logPath = concat(applicationLocalStorageFolder, "\\errors.log");
    
        // Create full hmm and dict file paths
        auto ChmmFilePath = convertStringToChars(hmmFilePath);
        auto CdictFilePath = convertStringToChars(dictFilePath);
        char *hmmPath = concat(applicationInstallFolderPath, ChmmFilePath);
        char *dictPath = concat(applicationInstallFolderPath, CdictFilePath);
    
        // Create decoder config
        config = cmd_ln_init(NULL, ps_args(), TRUE,
            "-hmm", hmmPath,
            "-dict", dictPath,
            "-mmap", "yes",
            "-logfn", logPath,
            "-kws_threshold", "1.000000e+00",
            NULL);
    
        // Cleanup
        free(ChmmFilePath);
        free(CdictFilePath);
        free(logPath);
        free(hmmPath);
        free(dictPath);
    
        if (config == NULL)
            return "Could not create a config";
    
        decoder = ps_init(config);
        if (decoder == NULL)
            return "Could not create a decoder";
    
        initializedRecognitionType = RecognitionType::Grammatic;
        return "PocketSphinx initialized";
    }
    
     

    Last edit: Hamdan Prakoso 2016-07-26
    • Toine db

      Toine db - 2016-08-11

      Did you get it to run already?

      Personally I always tested new build models first on PocketSphinx_Continuous.... just to get direct feedback through command line.
      If you get it running with PocketSphinx_Continous you just have to user the same arguments in the config of the Windows Phone app.... like:

      config = cmd_ln_init(NULL, ps_args(), TRUE,
              "-hmm", hmmPath,
              "-dict", dictPath,
              "-mmap", "yes",
              "-logfn", logPath,
              "-kws_threshold", "1.000000e+00",
              NULL);
      
       

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.