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: