AndroidPocketSphinx: How does the system know which recognizer is invoked?
Asked Answered
E

2

4

I am studying the source code of TestPocketSphinxAndAndroidASR.java and the first thing that is not so clear to me is how the system knows which recognizer (i.e. Google or CMUSphinx) to invoke.

I can see that the recognition activity is started by:

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
  startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);

but as far as I know this code isn't specific to either GVR (Google Voice Search) or CMUSphinx.

So how does Android know which recognizer to start?

Earlier in onCreate(), there is a reference to an AndroidPocketSphinx setting:

mUsePocektSphinxASR = prefs.getBoolean(PreferenceConstants.PREFERENCE_USE_POCKETSPHINX_ASR, false);

but searching on the entire project yields only the next statement which uses this boolean to display a different Toast:

if (mUsePocektSphinxASR){
  Toast.makeText(TestPocketSphinxAndAndroidASR.this, "Would be working offline, using PocketSphinx Speech recognizer...", Toast.LENGTH_LONG).show();
}
else{
  Toast.makeText(TestPocketSphinxAndAndroidASR.this, "Working online, Using system speech recognizer (Google speech recognition server)... ", Toast.LENGTH_LONG).show();
}

So I don't understand how the system knows (based on that preference) which recognizer to start.

How does Android know which recognizer to start?

Erinn answered 4/9, 2013 at 1:42 Comment(2)
What is TestPocketSphinxAndAndroidASR.java? Please provide a link.Shiff
@Shiff Sorry, I didn't realize it is not easily findable. I initially thought this was part of the official PocketSphinxAndroidDemo but thanks to your question I realized this is actually a fork. See directly link to the file in the update above and the question still remains. How does the author accomplish this magic? Thanks.Erinn
S
2

Your question is not specific to speech recognition on Android. It's just a question about how intent resolution happens on Android.

Your code constructs an Intent and passes it to startActivityForResult which starts the corresponding activity. If there are several corresponding activities then Android pops up a choice dialog, or chooses automatically based on a user-set default. If e.g. Google Voice Search is automatically chosen then you can try to apply "clear defaults" to it in the Application Manager. Instructions for Samsung Galaxy S II running Android 4.1:

Settings -> Application manager -> All -> Google Search (v2.7.9...)
    -> Launch by default -> Clear defaults

The Google Search "Launch by default" setting should now show "No defaults set". Now, if you launch an activity that supports ACTION_RECOGNIZE_SPEECH and if in addition to Google Search you have one or more apps installed that support this intent, then you'll see the dialog. If for testing you need an app that supports ACTION_RECOGNIZE_SPEECH then install Kõnele. (I'm not sure that the CMU Sphinx based code that you reference actually implements this intent type, but I didn't check carefully.)

Shiff answered 6/9, 2013 at 12:24 Comment(1)
No choice dialog pops up. I know about intent resolution on Android but I can't seem to find that "user-set default". That PREFERENCE_USE_POCKETSPHINX_ASR is internal and appears to be unused throughout the system. Where is that "user-set default" in the intent resolution chain? Thanks +1 for now.Erinn
I
1

Android doesn't "know which recognizer to start" because selecting that "Test Both ASR" menu item (and function) doesn't mean that selecting that menu item will invoke either GVR or CMU based on the PREFERENCE_USE_POCKETSPHINX_ASR.

Instead, it means "only test GVR" and thus it will always start GVR.

The CMU testing is done via the existing "Hold and Speak" layout element.

Insurer answered 29/10, 2013 at 2:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.