List of usage examples for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL
String EXTRA_LANGUAGE_MODEL
To view the source code for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL.
Click Source Link
From source file:com.ferid.app.notetake.MainActivity.java
/** * Voice listener/*from ww w. j a v a2s. c o m*/ */ private void listenToUser() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); try { startActivityForResult(intent, SPEECH_REQUEST_CODE); } catch (ActivityNotFoundException e) { Toast toast = Toast.makeText(context, getString(R.string.voiceRecognitionNotSupported), Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
From source file:com.ola.insta.BookingAcivity.java
/** * Showing google speech input dialog//from w w w . ja va 2s . com * */ 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_LANGUAGE, Locale.getDefault()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.speech_prompt)); try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), getString(R.string.speech_not_supported), Toast.LENGTH_SHORT) .show(); } }
From source file:conversandroid.RichASR.java
/** * Starts speech recognition after checking the ASR parameters * * @param language Language used for speech recognition (e.g. Locale.ENGLISH) * @param languageModel Type of language model used (free form or web search) * @param maxResults Maximum number of recognition results */// w w w .j av a 2s . c om public void listen(final Locale language, final String languageModel, final int maxResults) { Button b = (Button) findViewById(R.id.speech_btn); b.setEnabled(false); if ((languageModel.equals(RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) || languageModel.equals(RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH)) && (maxResults >= 0)) { // Check we have permission to record audio checkASRPermission(); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // Specify the calling package to identify the application intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName()); //Caution: be careful not to use: getClass().getPackage().getName()); // Specify language model intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel); // Specify how many results to receive. Results listed in order of confidence intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults); // Specify recognition language intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); Log.i(LOGTAG, "Going to start listening..."); this.startListeningTime = System.currentTimeMillis(); myASR.startListening(intent); } else { Log.e(LOGTAG, "Invalid params to listen method"); ((TextView) findViewById(R.id.feedbackTxt)).setText("Error: invalid parameters"); } }
From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java
/** * start broadcast speech to text. Result process in StartScreen *//*from w ww.j a v a2 s.co m*/ private void promptSpeechInput(Locale locale) { try { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale.getLanguage()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, LanguageWork.GetResourceString(context, "say")); getActivity().startActivityForResult(intent, 200); } catch (ActivityNotFoundException a) { Logs.SaveLog(context, a); Toast.makeText(context, LanguageWork.GetResourceString(context, "forbidden_option"), Toast.LENGTH_SHORT) .show(); } }
From source file:com.google.developers.actions.debugger.MainActivity.java
public void voiceSearch(View view) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // Specify the calling package to identify your application intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); // Display an hint to the user about what he should say. intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.try_play_dual_core)); // Given an hint to the recognizer about what the user is going to say intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); startActivityForResult(intent, RECOGNIZER_REQ_CODE); }
From source file:org.apache.cordova.nodialogspeechrecognizer.SpeechRecognizer.java
/** * Fire an intent to start the speech recognition activity. * * @param args/* w w w . j a v a2s .co m*/ * Argument array with the following string args: [req code][number * of matches][prompt string] */ private void startSpeechRecognitionActivity(JSONArray args) { int maxMatches = 1; String prompt = ""; String language = Locale.getDefault().toString(); try { if (args.length() > 0) { // Maximum number of matches, 0 means the recognizer decides String temp = args.getString(0); maxMatches = Integer.parseInt(temp); } if (args.length() > 1) { // Optional text prompt prompt = args.getString(1); } if (args.length() > 2) { // Optional language specified language = args.getString(2); } } catch (Exception e) { Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString())); } // Create the intent and set parameters final 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, cordova.getActivity().getPackageName()); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); if (maxMatches > 0) intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches); if (!prompt.equals("")) intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); try { Handler loopHandler = new Handler(Looper.getMainLooper()); loopHandler.post(new Runnable() { @Override public void run() { speech.startListening(intent); } }); } catch (Exception e) { Log.e("error", "er", e); } // cordova.startActivityForResult(this, intent, REQUEST_CODE); }
From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java
/** * Fire an intent to start the speech recognition activity. * * @param args Argument array with the following string args: [req code][number of matches] *//*from w w w . j a va2 s.c om*/ private void startSpeechRecognitionActivity(JSONArray args) { int maxMatches = 0; String language = Locale.getDefault().toString(); try { if (args.length() > 0) { // Maximum number of matches, 0 means the recognizer decides String temp = args.getString(0); maxMatches = Integer.parseInt(temp); } if (args.length() > 1) { // Language language = args.getString(1); } } catch (Exception e) { Log.e(TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString())); } // Create the intent and set parameters final 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,"voice.recognition.test"); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); if (maxMatches > 0) intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches); Handler loopHandler = new Handler(Looper.getMainLooper()); loopHandler.post(new Runnable() { @Override public void run() { recognizer.startListening(intent); } }); }
From source file:net.olejon.mdapp.Icd10Activity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: { NavUtils.navigateUpFromSameTask(this); return true; }//from ww w .ja v a2 s .c o m case R.id.icd10_menu_voice_search: { try { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "nb-NO"); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); startActivityForResult(intent, VOICE_SEARCH_REQUEST_CODE); } catch (Exception e) { new MaterialDialog.Builder(mContext).title(getString(R.string.device_not_supported_dialog_title)) .content(getString(R.string.device_not_supported_dialog_message)) .positiveText(getString(R.string.device_not_supported_dialog_positive_button)) .contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue).show(); } return true; } default: { return super.onOptionsItemSelected(item); } } }
From source file:com.surveyorexpert.TalkToMe.java
private void sendRecognizeIntent() { // Intent /*w w w.j a v a 2s . co m*/ intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Press when complete"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(intent, SPEECH_REQUEST_CODE); // Toast.makeText(getBaseContext(),"TalkToMe Done" , Toast.LENGTH_LONG).show(); }
From source file:com.glabs.homegenie.util.VoiceControl.java
public void startListen() { _recognizer = getSpeechRecognizer(); _recognizer.setRecognitionListener(this); ///*from w w w . j a v a 2 s .c o m*/ //speech recognition is supported - detect user button clicks //start the speech recognition intent passing required data Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); //indicate package //recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); //message to display while listening recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Your wish is my command!"); //set speech model recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); //specify number of results to retrieve recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); //start listening //startActivityForResult(listenIntent, VR_REQUEST); //startActivityForResult(recognizerIntent, VR_REQUEST); _recognizer.startListening(recognizerIntent); }