Setting up PocketSphinx library in my own Android application

I am trying to implement Speech Recognition using Pocket Sphinx Library .

What was my approach

I just downloaded their demo project for Android. Imported it into Eclipse, cleaned it up, and ran it on the device. He worked successfully.

After that, I copied the libs folder from the demo project to my own project. I copied the contents of the assets folder as it is in my own project. Then I edited the contents of the digits.gram file according to this post .

Then implemented Listener in my activity and added addKeywordSearch to it.

My questions:

  • Is this approach right for implementing this library in our own projects? Can we just copy all the files, change the .gram files as needed and run it? Or do we need to take several other steps to create .gram files?

  • When I tried to use the above approach, the project successfully ran several times on the device. But after that, he began to show the following error.

     E/cmusphinx(10470): ERROR: "kws_search.c", line 158: The word '/1e-20/' is missing in the dictionary E/AndroidRuntime(10470): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uwemo.myvdemo/com.uwemo.myvdemo.MainActivity}: java.lang.RuntimeException: Decoder_setSearch returned -1 

However, /1e-20/ exists in my digits.gram file.

digits.gram file contents:

 up /1e-20/ down /1e-15/ left /1e-15/ right /1e-15/ here /1e-15/ 
  1. I noticed one thing: when I make a clean build of the Pocket Sphinx demo project and run it, it updates the digits.gram.md5 files. But when I copied everything into my project and made it cleant-build, these files were not recreated. This is normal?

  2. Do I need to have all the files in our project, as in a demo project? Or can I delete some unused files from my own project? Any list of necessary files (either in the resource folder, or in libraries or others) will be very useful.

Please let me know which approach should I successfully implement in my own project.

My activity code

 public class MainActivity extends Activity implements RecognitionListener{ private static final String DIGITS_SEARCH = "digits"; private 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); Toast.makeText(getApplicationContext(), "Speech Recognizer Started", Toast.LENGTH_SHORT).show(); } catch (IOException e){ e.printStackTrace(); } } @Override public void onBeginningOfSpeech() { // TODO Auto-generated method stub } @Override public void onEndOfSpeech() { // TODO Auto-generated method stub reset(); } @Override public void onPartialResult(Hypothesis arg0) { // TODO Auto-generated method stub } @Override public void onResult(Hypothesis hypothesis) { // TODO Auto-generated method stub if (hypothesis != null){ String text = hypothesis.getHypstr(); Toast.makeText(getApplicationContext(), "you got ::"+text, Toast.LENGTH_SHORT).show(); } } private void setupRecognizer(File assetsDir){ File modelsDir = new File(assetsDir, "models"); recognizer = defaultSetup().setAcousticModel(new File(modelsDir, "hmm/en-us-semi")) .setDictionary(new File(modelsDir, "dict/cmu07a.dic")) .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f) .getRecognizer(); recognizer.addListener(this); File digitsGrammar = new File(modelsDir, "grammar/digits.gram"); recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar); reset(); } private void reset(){ recognizer.stop(); recognizer.startListening(DIGITS_SEARCH); } } 

My project structure is consistent

enter image description here

+1
java android pocketsphinx pocketsphinx-android
Jul 21 '15 at 15:04
source share

No one has answered this question yet.

See similar questions:

52
Android: speech recognition without using google server
17
Multiple Keyword Recognition with PocketSphinx

or similar:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
947
Android Studio: add jar as a library?
-2
Java: the program closes when it should listen



All Articles