我正在尝试解析 Android Voice Recognition Activity 的结果,并发现所有单词(用空格分隔)都在数组的第一个索引中。
我期待它将所有单词放入数组的每个索引中。
private void startVoiceRecognitionActivity()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
long wait = 10000;
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, wait);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Now");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK)
{
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
/*mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches)); */
//start intent after we get list of items
mListIntent = new Intent();
mListIntent.setClassName(Consts.CLASS_PATH,
ActivityUtil.getInstance().getClassName()); //get class name based
//on current activity
//now set array 'matches' from above and send to next activity...
Bundle bundle = new Bundle();
bundle.putStringArrayList(Consts.BUNDLE_KEY_VOICE_LIST, matches);
mListIntent.putExtras(bundle);
startActivity(mListIntent);
//TODO: also how do we add to google dictionary?
}
super.onActivityResult(requestCode, resultCode, data);
}