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
<pre name="code" class="java">@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 result. The android Speech Recognition service returns the result in the ArrayList <String> format. The following code:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); ArrayList<String> results = data .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); Log.i("zpf", results.get(0).toString()); }
In addition, you must add the following in the configuration file:
<uses-permission android:name="android.permission.RECORD_AUDIO" /><uses-permission android:name="android.permission.INTERNET" />
How can I complete speech recognition without the "speak" dialog box when calling the iflytek voice API?
Continue to call the API: showwindow hides the dialog box, but uses its handle to call the findwindow and other APIs.
Is there an example of android Speech Recognition? Thank you very much for not calling the system speech software.
Baidu yixun Feifei voice API, which provides detailed examples. I hope I can help you and ask me if I have any questions.