Android uses voice recognition dialogs such as Google Voice, Baidu voice, And xunfei voice by calling system interfaces.

Source: Internet
Author: User

Android uses voice recognition dialogs such as Google Voice, Baidu voice, And xunfei voice by calling system interfaces.

Currently, the app development process integrates some speech recognition functions. Generally, developers do not have the ability to develop their own voice recognition engines, therefore, in most cases, select a mature speech recognition engine SDK and integrate it into your app.

Generally, there are two types of integration: one is to directly call the SDK to design a pop-up box for the developer, and the developer does not need to develop a recognition interactive interface; in addition, developers only use the speech recognition service provided by the SDK to develop their own interactive design.

This article describes how to directly call the pop-up box.

First, the test machine needs to install voice software for products such as Google Voice, Baidu voice, And xunfei voice. In this case, you can find the relevant speech recognition function list in the language and input field on the system settings interface. Then you can call it directly.

The following are the call steps:

First, an intent instance is used in the Activity. The intent action is set to RecognizerIntent. ACTION_RECOGNIZE_SPEECH or RecognizerIntent. ACTION_WEB_SEARCH. For RecognizerIntent, you can view previous articles in this blog and call an operation that

@Override        public void onClick(View v) {           Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);     //Intent intent=new Intent(RecognizerIntent.ACTION_WEB_SEARCH);           startActivityForResult(intent, 0);        }



Then, retrieve the result with the string RecognizerIntent. EXTRA_RESULTS in the returned results. The android Speech Recognition Service uses the results in the ArrayList The following code is returned:

 @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        super.onActivityResult(requestCode, resultCode, data);        ArrayList
   
     results = data                .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);        Log.i("zpf", results.get(0).toString());    }
   

In addition, you must add the following in the configuration file:

   
   


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.