【问题标题】:Android Voice Recognition All results in one index of arrayAndroid语音识别所有结果都在一个数组索引中
【发布时间】:2011-06-02 16:48:30
【问题描述】:

我正在尝试解析 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);
}

【问题讨论】:

    标签: android voice-recognition


    【解决方案1】:

    你在这一行有一个额外的报价:

    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Now" ");
    

    只需将其删除。
    它可能会起作用。

    【讨论】:

      【解决方案2】:

      现在才发现这个。如果其他人发现这一点,则问题不在于额外的语音标记(尽管这会停止代码编译)。

      问题在于用户对匹配中返回的内容的理解 (RecognizerIntent.EXTRA_RESULTS)。这个数组不是每个单词都有一个条目,它对于语音识别器与它认为你可能说过的每一个匹配项都有一个条目。

      例如如果你说“我在 Stack Overflow 上写过”,那么数组可能是:

      ["I wrote on stack overflow",
       "I boat a stack over flow",
       "Ire oh ton stack over flow"]
      

      如果你想得到一个单词数组,我建议取第一个匹配字符串并分割所有空格。

      【讨论】:

        【解决方案3】:

        我已经给出了一个运行代码,你可以复制粘贴它就完成了..here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-02-20
          • 1970-01-01
          • 2013-06-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-05
          • 1970-01-01
          相关资源
          最近更新 更多