Current location - Recipe Complete Network - Complete cookbook of home-style dishes - How to complete the function of speech recognition without popping up the "Please Speak" dialog box when calling Iflytek Voice API?
How to complete the function of speech recognition without popping up the "Please Speak" dialog box when calling Iflytek Voice API?
At present, some speech recognition functions will be integrated in the development process of app, but ordinary developers do not have to develop a speech recognition engine themselves, so in most cases, a mature speech recognition engine SDK will be selected to integrate into their own app.

Usually, there are two kinds of integration. One is to directly call the pop-up box designed by SDK for developers, and developers do not need to develop an interactive interface. Another is that developers only use the speech recognition service provided by SDK to develop their own interaction design.

This paper introduces the simplest method to adjust the pop-up box directly.

First, testers need to install the voice software of Google Voice, Baidu Voice, Iflytek Voice and other products. At this point, you can find a list of related speech recognition functions in the language and input of the system setting interface. Then you can call it directly.

The following steps are called:

First, an intention is instantiated in the activity, and the action of the intention is set to RecognizerIntent. Action _ Recognition _ Speech or recognizer intent. Action _ Network _ Search. You can check the previous article about the recognizer's intention in this blog, and then call an operation with a return result.

& lt pre name = "code" class = "Java" > @ overwrite.

Public void onClick (view v)

Intent Intent = new Intent(recognizer Intent。 Action _ recognition _ voice);

//Intent Intent = new Intent(recognizer Intent。 ACTION _ WEB _ SEARCH);

startActivityForResult(intent,0);

}

Then, the result corresponding to the character string recognition content is taken out. Extra _ results comes from the returned results, and the android speech recognition service will unify the results with ArrayList.

@ Overlay

Protected void on activity result (int request code, int resultCode, intent data) (

super . on activity result(request code,resultCode,data);

ArrayList & lt string & gt result = data

. getStringArrayListExtra(recognizer intent。 EXTRA _ RESULTS);

Log.i("zpf ",results.get(0)。 toString());

}

In addition, you need to add:

& ltuses-permission Android:name = " Android . permission . record _ AUDIO "/& gt;

& ltuses-permission Android:name = " Android . permission . internet "/& gt;