List of usage examples for android.speech RecognizerIntent EXTRA_LANGUAGE_PREFERENCE
String EXTRA_LANGUAGE_PREFERENCE
To view the source code for android.speech RecognizerIntent EXTRA_LANGUAGE_PREFERENCE.
Click Source Link
From source file:com.vyasware.vaani.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); returnedText = (TextView) findViewById(R.id.textView1); outputText = (TextView) findViewById(R.id.textView2); progressBar = (ProgressBar) findViewById(R.id.progressBar1); toggleButton = (ToggleButton) findViewById(R.id.toggleButton1); progressBar.setVisibility(View.INVISIBLE); speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, // "en"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName()); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override/*from ww w . j av a 2s. c o m*/ public void onInit(int status) { if (status != TextToSpeech.ERROR) { tts.setLanguage(new Locale("hi_IN")); tts.setSpeechRate(0.9f); } } }); returnedText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, returnedText.getText()); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); } }); toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(true); speech.startListening(recognizerIntent); outputText.setText(""); } else { progressBar.setIndeterminate(false); progressBar.setVisibility(View.INVISIBLE); speech.stopListening(); } } }); }
From source file:ai.api.unityhelper.RecognitionHelper.java
/** * * @param lang recognition language/*from w w w . j a v a 2 s.com*/ */ private void startListening(final String lang) { if (!recognitionActive) { final Intent sttIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); final String language = lang.replace('-', '_'); sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language); // WORKAROUND for https://code.google.com/p/android/issues/detail?id=75347 // TODO Must be removed after fix in Android sttIntent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[] {}); runInUiThread(new Runnable() { @Override public void run() { initializeRecognizer(); speechRecognizer.startListening(sttIntent); recognitionActive = true; } }); } else { Log.w(TAG, "Trying to start recognition while another recognition active"); } }
From source file:com.ksutopia.bbtalks.plugins.P201SpeechToText.java
/** * Fire an intent to start the speech recognition activity. */*from w ww . j a v a 2 s. co m*/ * @param args Argument array with the following string args: [req code][number of matches][prompt string] */ private void startSpeechRecognitionActivity(JSONArray args) { int maxMatches = 0; 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 speech = SpeechRecognizer.createSpeechRecognizer(context); recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, context.getPackageName()); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); if (maxMatches > 0) recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches); if (!prompt.equals("")) recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); speech.setRecognitionListener(listener); speech.startListening(recognizerIntent); }
From source file:com.pixplicity.castdemo.MainActivity.java
/** * Android voice recognition//from w ww .ja 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:com.wizardsofm.deskclock.alarms.AlarmActivity.java
public void startListening() { makeText(this, getResources().getString(R.string.prompt_voice_commands), Toast.LENGTH_SHORT).show(); speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en"); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName()); // intent.putExtra("android.speech.extra.DICTATION_MODE", true); speech.startListening(intent);/*from www. j a v a 2 s.co m*/ resumeCounting = true; keepListening(); }