Android的RecognizerIntent语音识别 [英] Android RecognizerIntent Speech recognition

查看:362
本文介绍了Android的RecognizerIntent语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理图像(ImageView的)事件中的RecognizerIntent完成的知名度,由于用户不说话

How to handle the visibility of an image(ImageView) in the event the RecognizerIntent finishes due to the user not speaking

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

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

日Thnx

推荐答案

在code以上你只是测试,如果常量是零,而他们没有。你必须用

In the code above you are just testing if the constants are null, which they are not. You have to start the recognition somewhere in the code by

    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。例如,见<一href=\"http://stackoverflow.com/questions/6316937/how-can-i-use-speech-recognition-without-the-annoying-dialog-in-android-phones\">this问题。

A more customizable way is to use SpeechRecognizer directly. See for example this question.

这篇关于Android的RecognizerIntent语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆