Example usage for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM

List of usage examples for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM

Introduction

In this page you can find the example usage for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM.

Prototype

String LANGUAGE_MODEL_FREE_FORM

To view the source code for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM.

Click Source Link

Document

Use a language model based on free-form speech recognition.

Usage

From source file:nl.hnogames.domoticz.SpeechSettingsActivity.java

private void startRecognition() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (PermissionsUtil.canAccessAudioState(this)) {
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());

            speechRecognizer.startListening(intent);
            listeningSpeechRecognition = true;
            playRecognitionAnimation();/*w  w  w  . j a  v a2s  .c o m*/
        } else {
            permissionHelper.request(PermissionsUtil.INITIAL_AUDIO_PERMS);
        }
    } else {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        speechRecognizer.startListening(intent);

        listeningSpeechRecognition = true;
        playRecognitionAnimation();
    }
}

From source file:conversandroid.RichASR.java

/**
 * Shows in the GUI the default values for the language model (checks radio button)
 * and the maximum number of recognition results (shows the number in the text field)
 *//*from  w w  w.  j a v  a2 s .  c o  m*/
private void showDefaultValues() {
    //Show the default number of results in the corresponding EditText
    ((EditText) findViewById(R.id.numResults_editText)).setText("" + DEFAULT_NUMBER_RESULTS);

    //Show the language model
    if (DEFAULT_LANG_MODEL.equals(RecognizerIntent.LANGUAGE_MODEL_FREE_FORM))
        ((RadioButton) findViewById(R.id.langModelFree_radio)).setChecked(true);
    else
        ((RadioButton) findViewById(R.id.langModelFree_radio)).setChecked(true);
}

From source file:root.magicword.MagicWord.java

private void sendRecognizeIntent() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the magic word");
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
    startActivityForResult(intent, SPEECH_REQUEST_CODE);
}

From source file:org.gots.ui.NewSeedActivity.java

@Override
public void onClick(View v) {
    newSeed.setDescriptionDiseases(descriptionDiseases.getText().toString());
    newSeed.setDescriptionCultivation(descriptionEnvironment.getText().toString());
    newSeed.setDescriptionHarvest(descriptionHarvest.getText().toString());
    newSeed.setDescriptionGrowth(descriptionGrowth.getText().toString());
    Intent intent;/* w  ww.  ja  v a2  s  .c  o m*/
    switch (v.getId()) {
    case R.id.imageBarCode:
        scanBarCode();
        break;

    case R.id.buttonStock:
        if (validateSeed()) {
            new AsyncTask<Void, Integer, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    if (picturePath != null) {
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        Bitmap bitmap = FileUtilities.decodeScaledBitmapFromSdCard(picturePath, 100, 100);
                        bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
                        byte[] bitmapdata = bos.toByteArray();

                        // write the bytes in file
                        FileOutputStream fos;
                        try {
                            fos = new FileOutputStream(new File(gotsPrefs.getGotsExternalFileDir(),
                                    newSeed.getVariety().toLowerCase().replaceAll("\\s", "")));
                            fos.write(bitmapdata);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        newSeed = seedManager.createSeed(newSeed, new File(picturePath));
                    } else
                        newSeed = seedManager.createSeed(newSeed, null);
                    // seedManager.attach
                    seedManager.addToStock(newSeed, gardenManager.getCurrentGarden());
                    return null;
                }

                protected void onPostExecute(Void result) {
                    getApplicationContext().sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));
                    NewSeedActivity.this.finish();

                };
            }.execute();

        }
        break;

    case R.id.buttonModify:
        if (validateSeed()) {

            new AsyncTask<Void, Integer, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    seedManager.updateSeed(newSeed);
                    return null;
                }

                protected void onPostExecute(Void result) {
                    getApplicationContext().sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));
                    NewSeedActivity.this.finish();

                };
            }.execute();

        }
        break;

    case R.id.IdSeedDescriptionCultureVoice:
        intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, REQUEST_GROWTH);
        break;
    case R.id.IdSeedDescriptionEnnemiVoice:
        intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, REQUEST_DISEASES);
        break;
    case R.id.IdSeedDescriptionEnvironmentVoice:
        intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, REQUEST_ENVIRONMENT);
        break;
    case R.id.IdSeedDescriptionHarvestVoice:
        intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, REQUEST_HARVEST);
        break;

    // case R.id.buttonCatalogue:
    // if (validateSeed()) {
    // seedManager.createSeed(newSeed);
    // finish();
    // }
    // break;
    default:
        break;
    }

}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java

private void promptSpeechInput() {
    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0);
    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, "Say Something");
    try {/*from  w w  w  .  ja v  a 2 s  .  c o  m*/
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getActivity().getApplicationContext(), "Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:conversandroid.RichASR.java

/**
 * Reads the values for the language model and the maximum number of recognition results
 * from the GUI//from  w  w  w .  j  a  va  2s  .c  om
 */
private void setRecognitionParams() {
    String numResults = ((EditText) findViewById(R.id.numResults_editText)).getText().toString();

    //Converts String into int, if it is not possible, it uses the default value
    try {
        numberRecoResults = Integer.parseInt(numResults);
    } catch (Exception e) {
        numberRecoResults = DEFAULT_NUMBER_RESULTS;
    }
    //If the number is <= 0, it uses the default value
    if (numberRecoResults <= 0)
        numberRecoResults = DEFAULT_NUMBER_RESULTS;

    RadioGroup radioG = (RadioGroup) findViewById(R.id.langModel_radioGroup);
    switch (radioG.getCheckedRadioButtonId()) {
    case R.id.langModelFree_radio:
        languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
        break;
    case R.id.langModelWeb_radio:
        languageModel = RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH;
        break;
    default:
        languageModel = DEFAULT_LANG_MODEL;
        break;
    }
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void promptSpeechInput(EditText e) {
    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(e.getWindowToken(), 0);
    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, "Say Something");
    try {/*w ww .  j a v a2 s. co  m*/
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getActivity().getApplicationContext(), "Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:sandra.examples.oneshot.voicelaunch.VoiceLaunch.java

/**
 * Listens for names of apps. Depending of the recognition results, the methods processError, processReadyForSpeech 
 * or processResults will be invoked./* w w w .j a  v  a2s .  c  om*/
 * Speech recognition is carried out in US English because it is the only language for which phonetic similarity
 * works
 */
private void startListeningForApps() {
    try {
        indicateListening();
        //Recognition model = Free form, Number of results = 1 (we will use the best result to perform the search)
        listen(RecognizerIntent.LANGUAGE_MODEL_FREE_FORM, 1); //Start listening
    } catch (Exception e) {
        Toast toast = Toast.makeText(getApplicationContext(), "ASR could not be started: invalid params",
                Toast.LENGTH_SHORT);
        toast.show();
        changeButtonAppearanceToDefault();
        Log.e(LOGTAG, "ASR could not be started: invalid params");
    }
}

From source file:root.gast.playground.speech.SpeechRecognitionPlay.java

/**
 * create the {@link RecognizerIntent} based on the many preferences
 *///w ww  .  j  a v a  2 s. c  o m
private Intent readRecognizerIntentFromPreferences() {
    Intent intentToSend;

    //web search handling
    boolean isWebSearchAction = preferences.getBoolean(this, R.string.pref_websearch,
            R.string.pref_websearch_default);

    boolean isHandsFreeAction = preferences.getBoolean(this, R.string.pref_handsfree,
            R.string.pref_handsfree_default);

    if (isWebSearchAction) {
        intentToSend = RecognizerIntentFactory.getWebSearchRecognizeIntent();
        final boolean ADD_ORIGIN = true;
        if (ADD_ORIGIN && Build.VERSION.SDK_INT >= 14) {
            intentToSend.putExtra(RecognizerIntent.EXTRA_ORIGIN, true);
        }
    } else {
        if (isHandsFreeAction && Build.VERSION.SDK_INT >= 16) {
            intentToSend = RecognizerIntentFactory.getHandsFreeRecognizeIntent();
        } else {
            intentToSend = RecognizerIntentFactory.getBlankRecognizeIntent();
        }
    }

    //language model
    boolean isFreeFormModel = preferences.getBoolean(this, R.string.pref_languagemodel,
            R.string.pref_languagemodel_default);
    if (isFreeFormModel) {
        intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    } else {
        intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    }

    //common extras
    String language = preferences.getString(getResources().getString(R.string.pref_language),
            getResources().getString(R.string.pref_language_default));
    intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    String prompt = getResources().getString(R.string.speech_prompt) + ": "
            + whatYouAreTryingToSay.getText().toString();
    intentToSend.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    intentToSend.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
            preferences.getInt(this, R.string.pref_maxresults, R.string.pref_maxresults_default));
    intentToSend.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,
            preferences.getBoolean(this, R.string.pref_partial, R.string.pref_partial_default));

    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
            R.string.pref_complete_silence, R.string.pref_complete_silence_default, intentToSend);
    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS,
            R.string.pref_minimum_input_length, R.string.pref_minimum_input_length_default, intentToSend);
    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
            R.string.pref_possibly_complete_silence_length,
            R.string.pref_possibly_complete_silence_length_default, intentToSend);

    //pendingIntent handling
    boolean doPending = preferences.getBoolean(this, R.string.pref_withpendingintent,
            R.string.pref_withpendingintent);
    if (doPending) {
        Intent pendingIntentSource = new Intent(this, SpeechRecognitionResultsActivity.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0, pendingIntentSource, 0);

        Bundle extraInfoBundle = new Bundle();
        // pass in what you are trying to say so the results activity can
        // show it
        extraInfoBundle.putString(SpeechRecognitionResultsActivity.WHAT_YOU_ARE_TRYING_TO_SAY_INTENT_INPUT,
                whatYouAreTryingToSay.getText().toString());
        // set the variables in the intent this is sending
        intentToSend.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pi);
        intentToSend.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, extraInfoBundle);
    }

    Log.d(TAG, "sending recognizer intent: " + intentToSend.getExtras().toString());
    return intentToSend;
}

From source file:com.example.castCambot.MainActivity.java

/**
  * Android voice recognition//w  ww.  ja  v  a  2  s.c  om
  */
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);
}