List of usage examples for android.speech RecognizerIntent EXTRA_RESULTS
String EXTRA_RESULTS
To view the source code for android.speech RecognizerIntent EXTRA_RESULTS.
Click Source Link
From source file:com.todoroo.astrid.voice.VoiceInputAssistant.java
/** * This callback-method has to be called from Fragment.onActivityResult within your fragment * with parameters directly on passthru.<br> * You can check in your fragment if it was really a RecognizerIntent that was handled here, * if so, this method returns true. In this case, you should call super.onActivityResult in your * fragment.onActivityResult.//from w w w . java2s . c o m * <p> * If this method returns false, then it wasnt a request with a RecognizerIntent, so you can handle * these other requests as you need. * * @param activityRequestCode if this equals the requestCode specified by constructor, then results of voice-recognition * @param resultCode * @param data * @return */ public boolean handleActivityResult(int activityRequestCode, int resultCode, Intent data, EditText textField) { boolean result = false; // handle the result of voice recognition, put it into the textfield if (activityRequestCode == this.requestCode) { // this was handled here, even if voicerecognition fails for any reason // so your program flow wont get chaotic if you dont explicitly state // your own requestCodes. result = true; if (resultCode == Activity.RESULT_OK) { // Fill the quickAddBox-view with the string the recognizer thought it could have heard ArrayList<String> match = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); // make sure we only do this if there is SomeThing (tm) returned if (match != null && match.size() > 0 && match.get(0).length() > 0) { String recognizedSpeech = match.get(0); recognizedSpeech = recognizedSpeech.substring(0, 1).toUpperCase() + recognizedSpeech.substring(1).toLowerCase(); if (append) textField.setText((textField.getText() + " " + recognizedSpeech).trim()); else textField.setText(recognizedSpeech); } } } return result; }
From source file:com.example.h156252.connected_cars.CarGrid.java
/** * Receiving speech input/*from w w w . ja v a 2 s .c o m*/ * */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQ_CODE_SPEECH_INPUT: { if (resultCode == RESULT_OK && null != data) { ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); message_to_be_sent = result.get(0); /* Toast.makeText(getApplicationContext(), "Sending message: " + message_to_be_sent.toUpperCase(), Toast.LENGTH_SHORT).show();*/ new VoiceTask().execute("http://connect-car.au-syd.mybluemix.net/api/Items/" + receiver_id); } break; } } }
From source file:com.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case RequestCode.TEXT_TO_SPEECH: { if (resultCode == Activity.RESULT_OK && data != null) { ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); searchForm.setText(text.get(0)); search(text.get(0));/* ww w . j a v a 2s. c om*/ } break; } default: break; } }
From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == REQ_VOICE_INPUT) { final String text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0); presenter.onVoiceInputResult(text); }/*from w w w . j a v a2 s . co m*/ } }
From source file:com.justplay1.shoppist.features.search.SearchFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQ_CODE_SPEECH_INPUT) { if (resultCode == Activity.RESULT_OK && null != data) { ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); searchView.setActivated(true); searchView.setText(result.get(0)); }/*from w w w. j a va 2 s .c o m*/ } }
From source file:conversandroid.SimpleASR.java
/** * Shows the formatted best of N best recognition results (N-best list) from * best to worst in the <code>ListView</code>. * For each match, it will render the recognized phrase and the confidence with * which it was recognized./*from w ww .j a v a2 s .com*/ */ @SuppressLint("InlinedApi") @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ASR_CODE) { if (resultCode == RESULT_OK) { if (data != null) { //Retrieves the N-best list and the confidences from the ASR result ArrayList<String> nBestList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); float[] nBestConfidences = null; if (Build.VERSION.SDK_INT >= 14) //Checks the API level because the confidence scores are supported only from API level 14 nBestConfidences = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES); //Creates a collection of strings, each one with a recognition result and its confidence //following the structure "Phrase matched (conf: 0.5)" ArrayList<String> nBestView = new ArrayList<String>(); for (int i = 0; i < nBestList.size(); i++) { if (nBestConfidences != null) { if (nBestConfidences[i] >= 0) nBestView.add(nBestList.get(i) + " (conf: " + String.format("%.2f", nBestConfidences[i]) + ")"); else nBestView.add(nBestList.get(i) + " (no confidence value available)"); } else nBestView.add(nBestList.get(i) + " (no confidence value available)"); } //Includes the collection in the ListView of the GUI setListView(nBestView); Log.i(LOGTAG, "There were : " + nBestView.size() + " recognition results"); } } else { //Reports error in recognition error in log Log.e(LOGTAG, "Recognition was not successful"); } //Enable button Button speak = (Button) findViewById(R.id.speech_btn); speak.setEnabled(true); } }
From source file:com.todoroo.astrid.voice.VoiceInputAssistant.java
/** * Can also be called from Fragment.onActivityResult to simply get the string result * of the speech to text, or null if it couldn't be processed. Convenient when you * don't have a bunch of UI elements to hook into. * @param activityRequestCode//from w ww . ja va2s. c om * @param resultCode * @param data * @return */ public String getActivityResult(int activityRequestCode, int resultCode, Intent data) { if (activityRequestCode == this.requestCode) { if (resultCode == Activity.RESULT_OK) { // Fill the quickAddBox-view with the string the recognizer thought it could have heard ArrayList<String> match = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); // make sure we only do this if there is SomeThing (tm) returned if (match != null && match.size() > 0 && match.get(0).length() > 0) { String recognizedSpeech = match.get(0); recognizedSpeech = recognizedSpeech.substring(0, 1).toUpperCase() + recognizedSpeech.substring(1).toLowerCase(); return recognizedSpeech; } } } return null; }
From source file:com.rfo.basic.Web.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case Run.VOICE_RECOGNITION_REQUEST_CODE: if (resultCode == RESULT_OK) { Run.sttResults = new ArrayList<String>(); Run.sttResults = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); }/*ww w .jav a 2 s .c o m*/ Run.sttDone = true; } }
From source file:tech.salroid.filmy.activities.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (matches != null && matches.size() > 0) { String searchWrd = matches.get(0); if (!TextUtils.isEmpty(searchWrd)) { materialSearchView.setQuery(searchWrd, false); }/*from www. ja v a2s. co m*/ } return; } super.onActivityResult(requestCode, resultCode, data); }
From source file:rebus.gitchat.ui.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); searchView.populateEditText(matches); }/*from w ww . jav a 2 s. c o m*/ super.onActivityResult(requestCode, resultCode, data); }