2016-05-02 12 views
0

PocketSphinxで問題が発生しました。コードを実行するたびに、アプリケーションが自動的にシャットダウンします。私が何時間も働かない理由を理解しようとしているので、多分誰かが私を助けることができますか? :) これまでのコードは次のようになり、Pocketsphinx:App doesnt start

メイン:

public class MainActivity extends Activity implements RecognitionListener { 

    public SpeechRecognizer recognizer; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     try 
     { 
      Assets assets = new Assets(MainActivity.this); 
      File assetDir = assets.syncAssets(); 
      setupRecognizer(assetDir); 
     } 
     catch (IOException e) 
     { 
     } 

    } 

setupRecognizer:

private void setupRecognizer(File assetsDir) 
    { 

     try { 
      recognizer = defaultSetup() 
        .setAcousticModel(new File(assetsDir, "en-us-ptm")) 
        .setDictionary(new File(assetsDir, "cmudict-en-us.dict")) 
        .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f) 
        .setBoolean("-allphone_ci", true) 
        .getRecognizer(); 
      recognizer.addListener(this); 
      recognizer.addKeyphraseSearch("keywordsearch", "oh mighty Computer"); 
      recognizer.startListening("keywordsearch"); 

     } catch (IOException e) { 
     } 

onPartialResult:

public void onPartialResult(Hypothesis hyp) { 

    if (hyp == null) { 

    } 
    TextView t = (TextView) findViewById(R.id.textviewcontrol); 
    t.setText("found"); 
    recognizer.cancel(); 

} 

多分それは役立ちます。これまでのアプリこれらの行をコメントアウトすると、開始(=>テキストビューを表示します):

  recognizer.addKeyphraseSearch("keywordsearch", "oh mighty Computer"); 
      recognizer.startListening("keywordsearch"); 

私がそれらのうちの1つだけをコメントアウトすると、それは動作しません。

おそらく間違いがありますか?私はアンドロイド用のチュートリアルコードのようなものをすべてインポートしようとしましたが、私もそこで間違いを犯す可能性がありました。 ")recognizer.cancel(;"

Jannis

+1

例外を無視しないでください。 'e.printStackTrace()'を試してください –

+0

コンピュータは小文字でなければなりません。 "オハイオ巨大なコンピュータ" –

+0

多くの人に感謝、小文字は答えだった:) – JaBe

答えて

0

削除、ありがとうございましたonPartialResultメソッドからは、アプリが終了しているときにそれを使用します。

public void onDestroy() { 
     super.onDestroy(); 
     recognizer.cancel(); 
     recognizer.shutdown(); 
    }