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

爷,独闯天下 提交于 2019-12-10 17:34:37

问题


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?


回答1:


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.)




回答2:


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.



来源:https://stackoverflow.com/questions/18604166/androidpocketsphinx-how-does-the-system-know-which-recognizer-is-invoked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!