Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. private static final int SPEECH_REQUEST_CODE = 0;
  2.  
  3. // Create an intent that can start the Speech Recognizer activity
  4. private void displaySpeechRecognizer() {
  5. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  6. intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
  7. RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
  8. // Start the activity, the intent will be populated with the speech text
  9. startActivityForResult(intent, SPEECH_REQUEST_CODE);
  10. }
  11.  
  12. // This callback is invoked when the Speech Recognizer returns.
  13. // This is where you process the intent and extract the speech text from the intent.
  14. @Override
  15. protected void onActivityResult(int requestCode, int resultCode,
  16. Intent data) {
  17. if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
  18. List<String> results = data.getStringArrayListExtra(
  19. RecognizerIntent.EXTRA_RESULTS);
  20. String spokenText = results.get(0);
  21. // Do something with spokenText
  22. }
  23. super.onActivityResult(requestCode, resultCode, data);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement