欢迎来到天天文库
浏览记录
ID:33364708
大小:57.80 KB
页数:2页
时间:2019-02-25
《语音识别根据语音执行对应操作》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、在iphone4s发布后,siri语音功能成为了一时成为了热点,这几天想写个类似于siri类似功能的android应用,下面就是关键的两个技术点1语音识别:1.privatestaticfinalintVOICE_RECOGNITION_REQUEST_CODE=1234;2.3. /**4. *开启语音识别对话窗体5. */6. privatevoidstartVoiceRecognitionActivity(){7. Intentintent=newIntent(RecognizerIntent.AC
2、TION_RECOGNIZE_SPEECH);8. intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,9. RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);10. intent.putExtra(RecognizerIntent.EXTRA_PROMPT,11. "Speechrecognitiondemo");12. startActivityForResult(int
3、ent,VOICE_RECOGNITION_REQUEST_CODE);13. }14.15. /**16. *处理语音对话框返回的识别信息.17. */18. @Override19. protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){20. if(requestCode==VOICE_RECOGNITION_REQUEST_CODE21. &&resultCode==RESULT_OK){
4、22. //获取反馈的语音识别数组,并按照匹配度反馈23. 24. ArrayListmatches=data25. .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);26.1. 2. }3. 4. }复制代码2根据指令,进行打电话,发短信,打开网站操作:1.if(voicekey.type==1){//电话2. 3.
5、 txtview_secretary.setText("正在为你接通电话...");4. Thread.sleep(1000);5. Intentintent=newIntent(Intent.ACTION_CALL);6. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);7. intent.setData(Uri.parse("tel://"+voicekey.data));8. startA
6、ctivity(intent);9. }elseif(voicekey.type==2){//短信10. 11. txtview_secretary.setText("正在为你发短信...");12. Thread.sleep(1000);13. Intentintent=newIntent(Intent.ACTION_SENDTO,Uri.parse("sms:"+voicekey.data));14. startActiv
7、ity(intent);15. }16. elseif(voicekey.type==3)//网址17. {18. //openkitexplore,navigatetonetbank,closeApp19. txtview_secretary.setText("正在为你打开网站...");20. Thread.sleep(1000);21. Uriuri=Uri.parse(voicekey.data);22.
8、 Intentintent=newIntent(Intent.ACTION_VIEW,uri);23. startActivity(intent);24. }
此文档下载收益归作者所有