Android extras about speech recognition does not work

走远了吗. 提交于 2019-11-29 02:13:10

These parameters stopped working for Jelly Bean devices in a recent Google Search update. I've been meaning to file a bug report about if for a while. They still work for ICS devices and below.

If you want to continue to listen for a keyword without it timing out, you'll have to perform a loop, whereby you check for the keyword in onPartialResults. If Results is called and the keyword is not detected in those either, you need to immediately restart the recognition.

You'll need to handle the silent death bug and mute the system audio stream to prevent the Jelly Bean beep sound.

Those issues make the implementation very messy and frustrating. Sort it out Google....

This work only for Jelly Bean

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
    // Populate the wordsList with the String values the recognition
    // engine thought it heard
    ArrayList<String> matches = data
            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    wordsList.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, matches));
}
else {
finishActivity(REQUEST_CODE);
          startAndroidVoiceRecognition();
}
super.onActivityResult(requestCode, resultCode, data);
}  

public startAndroidVoiceRecognition()
{
    Intent intent = new Intent(
                    RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                    "Voice recognition Demo...");
            String defaultLanguage = Locale
                    .getDefault().toString();
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale
                    .getDefault());
    startActivityForResult(intent, REQUEST_CODE);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!