【问题标题】:Android RecognizerIntent Speech recognitionAndroid RecognizerIntent 语音识别
【发布时间】:2012-09-25 23:08:57
【问题描述】:

如果由于用户不说话而导致识别器意图完成,如何处理图像的可见性(ImageView)

if (RecognizerIntent.EXTRA_RESULTS == null){
image1.setVisibility(View.VISIBLE);///microphone icon
}

或

if (RecognizerIntent.ACTION_RECOGNIZE_SPEECH == null){
image1.setVisibility(View.INVISIBLE);///microphone
}

thnx

【问题讨论】:

    标签: android speech-recognition recognizer-intent


    【解决方案1】:

    在上面的代码中,您只是在测试常量是否为空,而它们不是。您必须通过

    在代码中的某处开始识别
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        //... put other settings in the Intent 
        startActivityForResult(intent, REQUEST_CODE);
    

    并在

    中接收结果
         @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data)
         {
           if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
             ArrayList<String> results = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
              //... do your stuf with results
             }
         super.onActivityResult(requestCode, resultCode, data);
         }
    

    更可定制的方式是直接使用 SpeechRecognizer。参见例如this question。

    【讨论】:

    • 太棒了。谢谢!!非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多