《语音识别根据语音执行对应操作》由会员分享,可在线阅读,更多相关《语音识别根据语音执行对应操作(2页珍藏版)》请在金锄头文库上搜索。
1、在iphone4s 发布后,siri语音功能成为了一时成为了热点,这几天想写个类似于siri类似功能的android应用,下面就是关键的两个技术点1 语音识别:1. private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;2.3. /*4. * 开启语音识别对话窗体5. */6. private void startVoiceRecognitionActivity() 7. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);8. inte
2、nt.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,9. RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);10. intent.putExtra(RecognizerIntent.EXTRA_PROMPT,11. Speech recognition demo);12. startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);13. 14.15. /*16. * 处理语音对话框返回的识别信息.17. */18. Override19. pr
3、otected void onActivityResult(int requestCode, int resultCode, Intent data) 20. if (requestCode = VOICE_RECOGNITION_REQUEST_CODE21. & resultCode = RESULT_OK) 22. / 获取反馈的语音识别数组,并按照匹配度反馈23. 24. ArrayList matches = data25. .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);26.27. 28. 29. 30. 复制代码
4、2 根据指令,进行打电话,发短信,打开网站操作:1. if (voicekey.type = 1) /电话2. 3. txtview_secretary.setText(正在为你接通电话.);4. Thread.sleep(1000);5. Intent intent = new Intent(Intent.ACTION_CALL);6. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);7. intent.setData(Uri.parse(tel:/ + voicekey.data);8. startActivity(intent);9. els
5、e if(voicekey.type = 2)/短信10. 11. txtview_secretary.setText(正在为你发短信.);12. Thread.sleep(1000);13. Intent intent = new Intent(Intent.ACTION_SENDTO,Uri.parse(sms:+voicekey.data);14. startActivity(intent);15. 16. else if(voicekey.type = 3) /网址17. 18. / open kit explore ,navigate to net bank,close App19. txtview_secretary.setText(正在为你打开网站.);20. Thread.sleep(1000);21. Uri uri = Uri.parse(voicekey.data);22. Intent intent = new Intent(Intent.ACTION_VIEW, uri);23. startActivity(intent);24.