<p><span style="color:rgb(68,68,68);">在<span style="font-family:Tahoma;">iphone4s </span><span style="font-family:宋体;">发布后,</span><span style="font-family:Tahoma;">siri</span><span style="font-family:宋体;">语音功能成为了一时成为了热点,这几天想写个类似于</span><span style="font-family:Tahoma;">siri</span><span style="font-family:宋体;">类似功能的</span></span><a target=_blank href="http://www.apkbus.com/"><span style="color:rgb(51, 102, 153);">android</span></a><span style="color:rgb(68,68,68);">应用,下面就是关键的两个技术点</span></p><p><span style="color:rgb(68,68,68);">1 <span style="font-family:宋体;">语音识别:</span></span></p>
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. intent.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. @Override 19. protected void onActivityResult(int requestCode, int resultCode, Intent data) { 20. if (requestCode == VOICE_RECOGNITION_REQUEST_CODE 21. && resultCode == RESULT_OK) { 22. // 获取反馈的语音识别数组,并按照匹配度反馈 23. 24. ArrayList<String> matches = data 25. .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 26. 27. 28. } 29.
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. } else 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 App 19. 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. }