




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
一、app
項目三:基于語音的飛行控實現(xiàn)功能:利用訊飛demo進行語音識別,并將識別結果發(fā)送到電腦端利用訊飛語音識別的算法提供的接口,寫出能夠識別漢語的activity。DatagramPacketpacket=newDatagramPacket(data,data.length,address,5600);DatagramSocketsocket=newDatagramSocket(); 電腦上的接收端的實現(xiàn)函數(shù)與上類似。“目標地址”中輸入電腦的IP地址,點“開始識別”,就可以說話了,識別器如果通信成功示范程序會輸出類似如下的結(顯示的是的IP地址指令對照Androidprivateprivatebyte[]GetMessageToSend(Stringstring){Stringmessage="NOP";message=}elseif(string.equals("降落")){message="LND";}elseif(string.equals("向前")){message="FWD";}elseif(string.equals("向后")){message="BCK";}elseif(string.equals("向左")){message="LFT";}elseif(string.equals("向右")){message="RGH";}elseif(string.equals("左轉")){message="CNT";}elseif(string.equals("右轉")){message="CLK";}elseif(string.equals("沖刺")){message="SPR";}return}packageimportjava.io.IOException;importjava.io.InputStream;importjavanet.DatagramPacket;importjavanet.DatagramSocket;importjavanet.InetAddress;importjavanet.SocketException;importjavaimportjava.util.List;importjava.util.Timer;importjava.util.TimerTask;importandroid.annotation.SuppressLint;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.app.Dialog;importandroid.content.Context;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.content.SharedPreferences.Editor;importandroid.content.pm.PackageInfo;importandroid.graphics.Typeface;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.os.RemoteException;importandroid.text.TextUtils;importandroid.util.Log;importandroid.util.Patterns;importandroid.view.Display;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.Window;importandroid.view.WindowManager;importandroid.widget.Button;importimportandroid.widget.SeekBar.OnSeekBarChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;importandroid.widget.SeekBar;importimportcom.iflytek.speech.GrammarListener;importcom.iflytek.speech.ISpee importcom.iflytek.speech.InitListener;importcom.iflytek.speech.LexiconListener;importcom.iflytek.speech.RecognizerListener;importcom.iflytek.speech.RecognizerResult;importcom.iflytek.speech.SpeechConstant;importcom.iflytek.speech.SpeechRecognizer;importcom.iflytek.speech.SpeechUtility;importcom.iflytek.speech.setting.AbnfSettings;importcom.iflytek.speech.util.ApkInstaller;importcom.iflytek.speech.util.JsonParser;importcom.iflytek.speech.util.XmlParser;publicclassAbnfDemoextendsActivityimplementsOnClickListener/*,privatestaticStringTAG="ARDroneSpeechDemo";privatestaticintPORT=5600;privateHandlermHandler;privateDialogmLoadDialog;//璇???寵?????privateSpeechRecognizermRecognizer;privateToastmToast;//緙?瀛privateSharedPreferencesmSharedPreferences;privateSharedPreferencesmParamPreferences;privateStringmLocalGrammar=null;privateStringmCloudGrammar=privatestaticfinalStringKEY_GRAMMAR_ABNF_ID="grammar_abnf_id";privatestaticfinalStringGRAMMAR_TYPE="abnf";privateStringmEngineType=privatebooleanrecognizing=false;privateintthreshold=50;publicvoidonCreate(Bundle{thisrequestWindowFeature(Window.FEATURE_NO_TITLE);mHandler=newMyhandler();mRecognizer=newSpeechRecognizer(this,mInitListener);mToast=ToastmakeText(this,"",Toast.LENGTH_SHORT);Timertimer=newTimer();//瀹?渚????Timer綾?timer.schedule(newTimerTask(){publicvoidrun(){}}privatevoidcheckAndInstallRecognizer(){finalDialogdialog=newLayoutInflaterinflater=ButtonokButton=(Button)alertDialogViewButtoncancelButton=(Button)alertDialogView.findViewById(R.id.cancel);TextViewcomeText=(TextView)alertDialogView.findViewById(R.id.title); spanString.setSpan(newStyleSpan(android.graphics.Typeface.BOLD_ITALIC),0,spanString.length(),SpannableString.SPAN_EXCLUSIVE_INCLUSIVE); TextViewcontentText=(TextView)alertDialogViewfindViewById(R.id.content);okButton.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv){mLoadDialog=newAlertDialog.Builder(AbnfDemo.this).create();Messagemessage=newMessage();}publicvoidonClick(Viewv){}WindowManagerwindowManager=getWindowManager();Displaydisplay=windowManager.getDefau WindowManager.LayoutParamslpdialog.getWindow().getAttributes();lp.width=(int)(display.getWidth());//璁劇疆瀹藉害}}classMyhandlerextendsHandler{publicvoidhandleMessage(Messagemsg){switch(msg.what){caseStringurl=StringassetsApk=if(processInstall(AbnfDemo.this,url,assetsApk)){Messagemessage=newMessage();message.what=1;}case1:if(mLoadDialog!=null){}}super}}*1.??存?ユ??寮?璇???蟲????$??浠朵??〉???錛?榪?琛?涓?privatebooleanprocessInstall(Contextcontext,Stringurl,String// //if(!ApkInstaller.installFromAssets(context,assetsApk)){Toast.makeText(AbnfDemo.this瀹?瑁?澶辮觸",return}return}StringpackageName=List<PackageInfo>packages=for(inti=0;i<packages.size();i++){PackageInfopackageInfo=packages.get(i);returntrue;}}return}*privatevoidinitLayout(){ finalTextViewtext_thre=((TextView)findViewById(R.id.text_thre));OnSeekBarChangeListener(){publicvoidonStopTrackingTouch(SeekBarseekBar)}publicvoidonStartTrackingTouch(SeekBarseekBar)}publicvoidonProgressChanged(SeekBarseekBar,intprogress,booleanfromUser){ifthreshold=progress;if(text_thre!=}}}//mSharedPreferences= mLocalGrammar=readFile("call.bnf","utf-8");mCloudGrammar=mLocalGrammar;mParamPreferences=getSharedPreferences(AbnfSettings.PREFER_NAME, }privateInitListenermInitListener=newInitListener()publicvoidonInit(ISpeeodulearg0,intcode){Log.d(TAG,"SpeechRecognizerinit()code="+code);if(code==ErrorCode.SUCCESS){}}publicvoidonClick(Viewview){{ case Intentintent=new case case int // result=mRecognizer.upda exicon("userword",readFile("userwords","utf-8"),lexiconListener); if(result== }{// result ","", if(result== caseR.id.isr_recognize:recognizing=true;caseR.id.isr_stop:caseR.id.isr_cancel:recognizing=false;}}privatevoidisr_recognize()mParamPreferences.getString("abnf_vadbos_preference","4000"));mParamPreferences.getString("abnf_vadeos_preference","50"));{StringgrammarId={}}{ }//mRecognizer.setParameter(SpeechConstant.PARAMS,"mixed_threshold=20");intrecode=mRecognizer.startListening(mRecognizerListener);if(recode!="+}privatevoidisr_build_grammar(){String[]mGrammars=newString[0];for(Stringgrammar:mGrammars){Log.d("",}StringgrammarContent;{grammarContent=newString(mCloudGrammar);}{grammarContent=newString(mLocalGrammar);}intret=mRecognizer.buildGrammar(GRAMMAR_TYPE,grammarContent,if(ret!="+}protectedvoidonDestroy(){} exiconListenerlexiconListener=newLexiconListener.Stub()publicvoidonLexiconUpdated(Stringarg0,intarg1)throwsRemoteExceptionif(ErrorCode.SUCCESS!=}publicvoidonBuildFinish(StringgrammarId,interrorCode)throwsRemoteException{if(errorCode==ErrorCode.SUCCESS){StringgrammarID=newString(grammarId);Editoreditor=mSharedPreferences.edit();editor.putString(KEY_GRAMMAR_ABNF_ID,grammarID);"+
"+}}*璇???????璋publicvoidonVolumeChanged(intv)throwsRemoteExceptionshowTip("onVolumeChanged錛?"+v);}publicvoidonResult(finalRecognizerResultresult,booleanisLast)throwsRemoteException{runOnUiThread(newRunnable(){publicvoidrun()if(null!=result){{Log.i(TAGrecognizerresult錛?result.getResultString());Stringtext=??Log.i(TAGrecognizerresult錛?result.getResultString());String[]text=??finalintconfidence=Integer.parseInt(text[1]);if(confidence>=Stringaddtext=((EditText)findViewById(R.id.test__ip)).getText().toString();//gettextbyte[]buf=GetMessageToSend(text[0]);InetAddressaddress;tryaddress=InetAddress.getByName(addtext);DatagramPacketpacket=newDatagramPacket(buf,buf.length,address,PORT);DatagramSocketsocket=newDatagramSocket(); }catch(UnknownHostExceptione){}catch(SocketExceptione)}catch(IOExceptione)}}if}}elseLog.d(TAG,"recognizerresult:}}}privatebyte[]GetMessageToSend(Stringstring)Stringmessage=ifstring.equals("璧烽??")){message="TKF";}elseif(string.equals("??????")){message="LND";}elseif(string.equals("??????")){message="FWD";}elseif(string.equals("??????")){message="BCK";}elseifstring.equals("???宸?")){me
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國白酒包裝行業(yè)市場全景調研及投資規(guī)劃建議報告
- “十三五”重點項目-無創(chuàng)血糖檢測儀項目節(jié)能評估報告(節(jié)能專)
- 第15課 兩漢的科技和文化 教學設計-部編版歷史與社會七年級上冊
- 機械制造工藝題庫(含參考答案)
- 中國立方相材料行業(yè)發(fā)展?jié)摿︻A測及投資戰(zhàn)略研究報告
- “十三五”重點項目-節(jié)水器生產建設項目可行性研究報告
- 2024中國農畜產品批發(fā)市場前景及投資研究報告
- 2024年生態(tài)修復未來趨勢預測分析及投資規(guī)劃研究建議報告
- 2025年掛鉤市場調研報告
- 2025-2030年中國氯銥酸氨行業(yè)深度研究分析報告
- 秦始皇嬴政人物生平介紹PPT
- 在馬克思墓前的講話說課稿公開課一等獎市賽課獲獎課件
- 農村電商(農產品電商)運營PPT完整全套教學課件
- 生理學人體生理功能的調節(jié)
- 骨科無痛病房的建立
- 口腔護理技術
- 塑料成型模具設計(第2版)江昌勇課件0-導論
- 《西藏度亡經》及中陰解脫竅決(收藏)
- POWERPOINT教學案例優(yōu)秀6篇
- 2022年內蒙古包頭市中考英語試卷含解析
- 五年級下冊《Lesson 11 Shopping in Beijing》教案冀教版三年級起點小學英語-五年級英語教案
評論
0/150
提交評論