3

Keith Vertanen の言語モデルの 1 つと組み合わせて、Android で PocketSphinx を使用して「ディクテーション」機能を実装しようとしています。サンプルを次のように変更しました。

private void setupRecognizer(File assetsDir) throws IOException {
 recognizer = defaultSetup()
     .setAcousticModel(new File(assetsDir, "en-us-ptm"))
     .setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
     .setRawLogDir(assetsDir)
     .setKeywordThreshold(1e-45f)
     .setBoolean("-allphone_ci", true)
      .getRecognizer();
  recognizer.addListener(this);
  File ngramModel = new File(assetsDir, "lm_csr_5k_nvp_2gram.arpa");
  recognizer.addNgramSearch(NGRAM_SEARCH, ngramModel);

lm_csr_5k_nvp_2gram.arpaKeith Vertanen のサイトの 5K NVP 2-gram ダウンロードからの場所です 。

次のエラーが表示されます。

1 18:04:29.861 2837-2863/? I/SpeechRecognizer: Load N-gram model /storage/emulated/0/Android/data/edu.cmu.sphinx.pocketsphinx/files/sync/lm_csr_5k_nvp_2gram.arpa
01-31 18:04:29.861 2837-2863/? I/cmusphinx: INFO: ngram_model_trie.c(399): Trying to read LM in trie binary format
01-31 18:04:29.861 2837-2863/? I/cmusphinx: INFO: ngram_model_trie.c(410): Header doesn't match
01-31 18:04:29.861 2837-2863/? I/cmusphinx: INFO: ngram_model_trie.c(177): Trying to read LM in arpa format
01-31 18:04:29.862 2837-2863/? E/cmusphinx: ERROR: "ngram_model_trie.c", line 103: Bad ngram count
01-31 18:04:29.862 2837-2863/? I/cmusphinx: INFO: ngram_model_trie.c(489): Trying to read LM in DMP format
01-31 18:04:29.862 2837-2863/? E/cmusphinx: ERROR: "ngram_model_trie.c", line 500: Wrong magic header size number a5c6461: /storage/emulated/0/Android/data/edu.cmu.sphinx.pocketsphinx/files/sync/lm_csr_5k_nvp_2gram.arpa is not a dump file
01-31 18:04:29.864 2837-2863/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                 Process: edu.cmu.sphinx.pocketsphinx, PID: 2837
                                                 java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                     at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                     at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                     at java.lang.Thread.run(Thread.java:818)
                                                  Caused by: 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:247)
                                                     at edu.cmu.pocketsphinx.demo.PocketSphinxActivity.setupRecognizer(PocketSphinxActivity.java:161)
                                                     at edu.cmu.pocketsphinx.demo.PocketSphinxActivity.access$000(PocketSphinxActivity.java:50)
                                                     at edu.cmu.pocketsphinx.demo.PocketSphinxActivity$1.doInBackground(PocketSphinxActivity.java:72)
                                                     at edu.cmu.pocketsphinx.demo.PocketSphinxActivity$1.doInBackground(PocketSphinxActivity.java:66)
                                                     at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                     at java.lang.Thread.run(Thread.java:818) 

台詞

01-31 18:04:29.861 2837-2863/? I/cmusphinx: INFO: ngram_model_trie.c(177): Trying to read LM in arpa format
01-31 18:04:29.862 2837-2863/? E/cmusphinx: ERROR: "ngram_model_trie.c", line 103: Bad ngram count

lm_csr_5k_nvp_2gram.arpaファイルが正しくフォーマットされていないか何かだと思います。ファイルは次のようになります。

\data\
ngram 1=5000
ngram 2=4331397
ngram 3=0

\1-grams:
-2.11154    </s>    0
-99 <s> -3.13167
-0.3954594  <unk>   -0.4365645
-2.271447   a   -2.953606
-3.384721   a.  -1.85196
-5.788997   a.'s    -0.8137056
-4.139672   abandoned   -0.9728376
-3.904189   ability -1.838658
-4.360272   able    -2.161723
...

これは、少なくともサンプル ファイルのように見えます

私の他の唯一の考えは、おそらく拡張子が間違っているということでし

言語モデルは、テキスト ARPA 形式、バイナリ形式 BIN、バイナリ DMP 形式の 3 つの異なる形式で保存およびロードできます。ARPA フォーマットはより多くのスペースを必要としますが、編集することは可能です。ARPA ファイルの拡張子は .lm です。バイナリ形式は、スペースが大幅に少なくて済み、読み込みが高速です。バイナリ ファイルの拡張子は .lm.bin です。フォーマット間の変換も可能です。DMP 形式は廃止され、推奨されません。

lm_csr_5k_nvp_2gram.lmこれにより、ファイルの名前を の代わりに付ける必要があるように聞こえますlm_csr_5k_nvp_2gram.arpa。ただし、例外を変更することなく、ファイルの名前を変更しようとしました。

これを行う正しい方法は何ですか?

4

2 に答える 2

2

これはモデル形式の問題です。ngram モデルの次の行が問題を引き起こします。

ngram 3=0

問題のある行を削除するか、 pocketphinx-android-demo を更新できます。この問題を修正した新しいバージョンをプッシュしました。

全体として、電話は非常に遅いため、電話でのディクテーションは簡単ではありません。2 グラムを使用することはお勧めしません。大幅にプルーニングされた 3 グラム モデルを使用することをお勧めします。srilm で剪定できます。

最適化のドキュメントを読んで、他に何を調整するかを学ぶこともできます。

于 2016-02-02T00:21:31.150 に答える
0

sphinx で以下のコマンドを使用して、arpa ファイルを言語モデル (lm) に変換します。

sphinx_lm_convert -i lm_csr_5k_nvp_2gram.arpa -o lm_csr_5k_nvp_2gram.lm.dmp

生成された言語モデルを Android プログラムで使用します。

recognizer.addNgramSearch(DIGITS_SEARCH,new File(assetsDir, "lm_csr_5k_nvp_2gram.lm.dmp"))
于 2017-04-02T05:24:13.173 に答える