Guest User

語音辨識

a guest
May 22nd, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. 先附上程式碼
  2. private OnClickListener Speech2Text = new OnClickListener() {
  3. public void onClick(View v) {
  4. // 啟動語音辨識
  5. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  6. intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LA
  7. intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "請說...");
  8. startActivityForResult(intent, 1);
  9. }
  10. };
  11. .
  12. .
  13. List<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
  14. Log.d(TAG, "result size = "+result.size());
  15. int maxresult = result.size();
  16. tv = (TextView) this.findViewById(R.id.editText1);
  17. tv.setText(result.toString());
  18. for(int x=0;x<maxresult;x++){
  19. String Get = result.get(x);
  20. String Comparison = new String("電話");
  21. flat = Get.compareTo(Comparison);
  22. if(flat == 0){
  23. Intent intent2 = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  24. intent2.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
  25. intent2.putExtra(RecognizerIntent.EXTRA_PROMPT, "請選擇電話組別...");
  26. startActivityForResult(intent2, 1);
  27.  
  28. List<String> result2 = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
  29. int maxresult_2 = result2.size();
  30. for(x=0;x<maxresult_2;x++){
  31. String Get_2 = result2.get(x);
  32. String P_Comparison = new String("第一");
  33. Log.d(TAG, "The P_Comparison String = " + P_Comparison);
  34. Log.d(TAG, "The result2 String = " + Get_2);
  35. Log.d(TAG, "開始電話比對動作…");
  36. flat2 = Get_2.compareTo(P_Comparison);
  37. if(flat2 == 0){
  38. Intent it = new Intent();
  39. it.setClass(MainActivity.this, contours.class);
  40. bundle=new Bundle();
  41. bundle.putString("myval_1", ptv1.getText().toString());
  42. it.putExtras(bundle);
  43. startActivityForResult(it, 0);
  44. }else Log.d(TAG, "辨識失敗...");
  45. }
  46. }else Log.d(TAG, "Get不等於電話");
  47. .
  48. .
Advertisement
Add Comment
Please, Sign In to add comment