Message Fly Voice Use step: Voice Turn text:
1, first to fly to the Open platform (http://www.xfyun.cn/) registration, account number:
2, login after registration:
3, click to select My Voice cloud:
4, click on the left sidebar to create a new application:
5, after the creation of a good application: as shown: Copy AppID:
6, Download SDK: Click on the left side of the SDK Download Center:
Select the features and platforms we need:
7, click the Download SDK, save the file, and open it.
//-----------------------------------------------------------
8, use Androidstudio to create a demo:
Layout file Contents:
<button
android:id= "@+id/btn_click"
android:text= "click to open the message to fly speech recognition"
android:layout_width= "Wrap_ Content "
android:layout_height=" wrap_content "
/>
<edittext
android:id=
" @+id/result " android:layout_below= "@id/btn_click"
android:layout_width= "match_parent"
android:layout_height= "Wrap_ Content "
android:hint=" here shows what you recorded "
/>
Effect:
9, will extract all the Libs in the file of the jar package, test to the Project Libs folder, refresh Gradle (Eclipse students can directly complete all tests such as Libs under, and Add Class Library):
9.1 Create a new folder under the main folder Jnilibs. Copy all except. jar folders in all SDK under Libs, with the. so file inside.
9,2, copy Assets folder to main below:
The effect is as follows:
To add permissions to the registration file:
<uses-permission android:name= "Android.permission.RECORD_AUDIO"/>
<uses-permission android:name= " Android.permission.INTERNET "/>
<uses-permission android:name=" Android.permission.ACCESS_NETWORK_STATE "/>
<uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE "/>
<uses-permission Android:name= "Android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name= " Android.permission.READ_PHONE_STATE "/>
<uses-permission android:name=" android.permission.ACCESS_FINE_ LOCATION "/>
<uses-permission android:name= android.permission.READ_CONTACTS"/>
< Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android: Name= "Android.permission.CAMERA"/>
In: mainactivity, add the following code:
Note that you need to copy your AppID to your code:
Package Zhaoq_qiang.xunfeidemo;
Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.Toast;
Import Com.iflytek.cloud.RecognizerResult;
Import com.iflytek.cloud.SpeechConstant;
Import Com.iflytek.cloud.SpeechError;
Import com.iflytek.cloud.SpeechUtility;
Import Com.iflytek.cloud.ui.RecognizerDialog;
Import Com.iflytek.cloud.ui.RecognizerDialogListener;
Import Org.json.JSONArray;
Import Org.json.JSONObject;
Import Org.json.JSONTokener;
public class Mainactivity extends Appcompatactivity implements View.onclicklistener {private Button btn_click;
Private EditText Mresulttext;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main); Btn_click = (Button) Findviewbyid (r.id.btn_cliCK);
Mresulttext = ((edittext) Findviewbyid (R.id.result));
Speechutility.createutility (This, speechconstant.appid + "= here is required to fill in the APPID you are applying for");
Btn_click.setonclicklistener (this);
@Override public void OnClick (View v) {btnvoice ();
//todo begins to speak: private void Btnvoice () {recognizerdialog dialog = new Recognizerdialog (this,null);
Dialog.setparameter (Speechconstant.language, "ZH_CN");
Dialog.setparameter (speechconstant.accent, "Mandarin"); Dialog.setlistener (New Recognizerdialoglistener () {@Override public void Onresult (Recognizerresul
T Recognizerresult, Boolean B) {Printresult (Recognizerresult);
@Override public void OnError (Speecherror speecherror) {}});
Dialog.show ();
Toast.maketext (This, "Please start Talking", Toast.length_short). Show (); }//callback result: private void Printresult (RecogniZerresult results) {String text = Parseiatresult (results.getresultstring ());
Automatically fill in the Address mresulttext.append (text);
public static string Parseiatresult (String json) {stringbuffer ret = new StringBuffer ();
try {jsontokener Tokener = new Jsontokener (JSON);
Jsonobject Joresult = new Jsonobject (Tokener);
Jsonarray words = Joresult.getjsonarray ("ws"); for (int i = 0; i < words.length (); i++) {//transliteration result word, default use first result jsonarray items = WORDS.G
Etjsonobject (i). Getjsonarray ("CW");
Jsonobject obj = items.getjsonobject (0);
Ret.append (Obj.getstring ("w"));
} catch (Exception e) {e.printstacktrace ();
return ret.tostring (); }
}
To run the program:
Effect as shown:
Demo:https://github.com/229457269/xunfeivoicedemo
Follow-up: The following needs to be online to fly to the application of the market steps, the author is not described, the developer completed the project packaging, through the audit, you can release the program, and access to the market users of the revenue.