List of usage examples for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM
String LANGUAGE_MODEL_FREE_FORM
To view the source code for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM.
Click Source Link
From source file:com.nicefontaine.seanachie.ui.imagestory.ImageStoryFragment.java
private Intent getSpeechIntent(String text) { return new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) .putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) .putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()) .putExtra(RecognizerIntent.EXTRA_PROMPT, text); }
From source file:com.pixplicity.castdemo.MainActivity.java
/** * Android voice recognition//from www .j a v a 2 s .c o m */ private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en-US"); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.message_to_cast)); startActivityForResult(intent, REQUEST_SPEECH_RECOGNITION); }
From source file:org.catrobat.catroid.ui.ScratchConverterActivity.java
public void displaySpeechRecognizer() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); startActivityForResult(intent, Constants.INTENT_REQUEST_CODE_SPEECH); }
From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java
/*** * Start the voice input activity manually *//*w w w . j a v a 2s . co m*/ public void startVoiceRecognition() { if (isMicEnabled()) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "pt-BR"); if (mContainerActivity != null) { mContainerActivity.startActivityForResult(intent, VOICE_RECOGNITION_CODE); } else if (mContainerFragment != null) { mContainerFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE); } else if (mContainerSupportFragment != null) { mContainerSupportFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE); } } }
From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java
private void setupFloatingSearch() { mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override//w ww.ja v a 2s . com public void onHomeClicked() { } }); mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, final String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { mSearchView.clearSuggestions(); } else { //this shows the top left circular progress //you can call it where ever you want, but //it makes sense to do it when loading something in //the background. mSearchView.showProgress(); //simulates a query call to a data source //with a new query. NumberDataHelper.findSuggestions(getApplicationContext(), newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY, new NumberDataHelper.OnFindSuggestionsListener() { @Override public void onResults(List<NumberSuggestion> results) { //this will swap the data and //render the collapse/expand animations as necessary mSearchView.swapSuggestions(results); //let the users know that the background //process has completed mSearchView.hideProgress(); } }); } Log.d(TAG, "onSearchTextChanged()"); } }); mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(final SearchSuggestion searchSuggestion) { NumberSuggestion numberSuggestion = (NumberSuggestion) searchSuggestion; NumberDataHelper.findNumbers(getApplicationContext(), numberSuggestion.getWord(), new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSuggestionClicked()"); mLastQuery = searchSuggestion.getWord(); } @Override public void onSearchAction(String query) { mLastQuery = query; NumberDataHelper.findNumbers(getApplicationContext(), query, new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSearchAction()"); } }); mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override public void onFocus() { //show suggestions when search bar gains focus (typically history suggestions) // NumberDataHelper cdh = new NumberDataHelper(); // cdh.setContext(getApplicationContext()); mSearchView.swapSuggestions(NumberDataHelper.getHistory(getApplicationContext(), 5)); Log.d(TAG, "onFocus()"); } @Override public void onFocusCleared() { //set the title of the bar so that when focus is returned a new query begins mSearchView.setSearchBarTitle(mLastQuery); //you can also set setSearchText(...) to make keep the query there when not focused and when focus returns //mSearchView.setSearchText(searchSuggestion.getWord()); Log.d(TAG, "onFocusCleared()"); } }); //handle menu clicks the same way as you would //in a regular activity mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() { @Override public void onActionMenuItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_refresh_list) { /*mIsDarkSearchTheme = true; //demonstrate setting colors for items mSearchView.setBackgroundColor(Color.parseColor("#787878")); mSearchView.setViewTextColor(Color.parseColor("#e9e9e9")); mSearchView.setHintTextColor(Color.parseColor("#e9e9e9")); mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9")); mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9")); mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9")); mSearchView.setDividerColor(Color.parseColor("#BEBEBE")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));*/ populateCardList(); } else if (item.getItemId() == R.id.action_voice_rec) { Intent voiceRecognize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); voiceRecognize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG"); voiceRecognize.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the letter in ARABIC..."); /*voiceRecognize.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); */ voiceRecognize.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(voiceRecognize, REQUEST_CODE); } else { //just print action //Toast.makeText(getApplicationContext().getApplicationContext(), item.getTitle(), // Toast.LENGTH_SHORT).show(); } } }); //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome" mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override public void onHomeClicked() { startActivity(new Intent(NumberViewActivity.this, MainActivity.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left); Log.d(TAG, "onHomeClicked()"); } }); /* * Here you have access to the left icon and the text of a given suggestion * item after as it is bound to the suggestion list. You can utilize this * callback to change some properties of the left icon and the text. For example, you * can load the left icon images using your favorite image loading library, or change text color. * * * Important: * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different * items in the list. */ mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { NumberSuggestion numberSuggestion = (NumberSuggestion) item; String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000"; String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878"; if (numberSuggestion.getIsHistory()) { leftIcon.setImageDrawable( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); } else { leftIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_lightbulb_outline_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); /*leftIcon.setAlpha(0.0f); leftIcon.setImageDrawable(null);*/ } textView.setTextColor(Color.parseColor(textColor)); String text = numberSuggestion.getWord().replaceFirst(mSearchView.getQuery(), "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>"); textView.setText(Html.fromHtml(text)); } }); //listen for when suggestion list expands/shrinks in order to move down/up the //search results list mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() { @Override public void onSuggestionsListHeightChanged(float newHeight) { mSearchResultsList.setTranslationY(newHeight); } }); }
From source file:com.google.sample.cast.refplayer.chatting.MainActivity.java
private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.message_to_cast)); startActivityForResult(intent, REQUEST_CODE); }
From source file:com.mhennessy.mapfly.MainActivity.java
public void setMapLocationBasedOnSpeech() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.mhennessy.mapfly"); SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(this.getApplicationContext()); // Stop flying so that messages can be displayed to the user without // being overwritten by pitch/roll info. setFlyingEnabled(false);//from w w w. j a va2 s. c o m RecognitionListener listener = new RecognitionListener() { @Override public void onResults(Bundle results) { ArrayList<String> voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); if (voiceResults == null) { Log.e(TAG, "No voice results"); } else { Log.d(TAG, "Printing matches: "); for (String match : voiceResults) { Log.d(TAG, match); } String bestMatch = voiceResults.get(0); setMapLocation(bestMatch); } } @Override public void onReadyForSpeech(Bundle params) { setTitle("Say something!"); Log.d(TAG, "Ready for speech"); } @Override public void onError(int error) { setTitle("Speach Error"); Log.d(TAG, "Error listening for speech: " + error); } @Override public void onBeginningOfSpeech() { Log.d(TAG, "Speech starting"); } @Override public void onBufferReceived(byte[] buffer) { // no-op } @Override public void onEndOfSpeech() { // no-op } @Override public void onEvent(int eventType, Bundle params) { // no-op } @Override public void onPartialResults(Bundle partialResults) { // no-op } @Override public void onRmsChanged(float rmsdB) { // no-op } }; recognizer.setRecognitionListener(listener); recognizer.startListening(intent); }
From source file:org.bishoph.oxdemo.OXDemo.java
public void startVoiceRecognitionActivity() { Log.v("OXDemo", "startVoiceRecognitionActivity init..."); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); if (activities.size() > 0) { intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); Log.v("OXDemo", "...done"); } else {/*from ww w . jav a 2 s . c o m*/ // createTask(folder_id, // "Auto creation "+getSimpleRandomString()); Log.v("OXDemo", "No voice recognition!"); } }
From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java
private void promptSpeechInput() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.voice_prompt)); startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); }
From source file:in.codehex.arrow.MainActivity.java
/** * Prompt the user to say something/*from w ww. j a v a 2 s. c o m*/ */ private void promptSpeechInput() { textToSpeech.stop(); intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); try { startActivityForResult(intent, Config.REQUEST_SPEECH_INPUT); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }