Menu

Why My PocketSphinx Cannot Load LM Bin from SDCard?

Help
2018-04-18
2018-04-19
  • Capt.Michael

    Capt.Michael - 2018-04-18

    Hi guys,

    I cloned https://github.com/cmusphinx/pocketsphinx-android-demo and it runs correctly on my Android phone. And I build my own language model bin file, place it to asset folder, and load by following code, it works fine!

    recognizer.addNgramSearch(CORPUS, new File(assetsDir, "corpus.lm.bin"));
    

    But after I put it to /sdcard, it cannot be loaded succeed any more, there's always an error says

    java.lang.RuntimeException: Decoder_setLmFile returned -1
      at edu.cmu.pocketsphinx.PocketSphinxJNI.Decoder_setLmFile(Native Method)
      at edu.cmu.pocketsphinx.Decoder.setLmFile(Decoder.java:172)
      at edu.cmu.pocketsphinx.SpeechRecognizer.addNgramSearch(SpeechRecognizer.java:259)
      at edu.cmu.pocketsphinx.demo.MainActivity.setupRecognizer(MainActivity.java:260)
      ...
    

    Please refer to following code, I try to load it from /storage/emulated/0/corpus.lm.bin, and lmFile is not null. And the second line is line 260 of MainActivity.java.

    File lmFile = new File(Environment.getExternalStorageDirectory(), "corpus.lm.bin");
    recognizer.addNgramSearch(CORPUS, lmFile);
    

    The only difference is path.

    How could I load language model bin file from storage? I have to, because my real language model bin file is too large to put it under asset folder.

    Thanks very much in advance!

     

    Last edit: Capt.Michael 2018-04-18
    • Nickolay V. Shmyrev

      You can check errors in logcat for details

       
      • Capt.Michael

        Capt.Michael - 2018-04-19

        @Nickolay,

        I just realized there's a filter remains in logcat, that makes me didn't see some logs, thanks for reminding!

        And now, detailed error message is:

        04-19 10:53:35.159 15363-15363/edu.cmu.sphinx.pocketsphinx E/cmusphinx: ERROR: "ngram_model_trie.c", line 356: File /storage/emulated/0/corpus.lm.bin not found
        04-19 10:53:35.159 15363-15363/edu.cmu.sphinx.pocketsphinx E/cmusphinx: ERROR: "ngram_model_trie.c", line 179: File /storage/emulated/0/corpus.lm.bin not found
        04-19 10:53:35.159 15363-15363/edu.cmu.sphinx.pocketsphinx E/cmusphinx: ERROR: "ngram_model_trie.c", line 447: Dump file /storage/emulated/0/corpus.lm.bin not found

        I've pushed corpus.lm.bin to /storage/emulated/0/, and I debugged, lmFile is NOT null at line which invokes addNgramSearch() method.

        File lmFile = new File(Environment.getExternalStorageDirectory(), "corpus.lm.bin");
        if (lmFile.isFile()) {
        recognizer.addNgramSearch(CORPUS, lmFile);
        }

        And of course, I've append READ_EXTERNAL_STORAGE permission to AndroidManifest.xml already.

        So, I'm wondering why ngram_model_trie.c cannot get such file?

        Thanks a lot!

         
        • Nickolay V. Shmyrev

          Try to open this file from java, maybe permission did not apply somehow.

           
          • Capt.Michael

            Capt.Michael - 2018-04-19

            Yes, you're right! God damn I forgot I run it on an Android 7.0 phone :(

            Thank you so much!

             

            Last edit: Capt.Michael 2018-04-19

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.