Example usage for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL

List of usage examples for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL

Introduction

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

Prototype

String EXTRA_LANGUAGE_MODEL

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

Click Source Link

Document

Informs the recognizer which speech model to prefer when performing #ACTION_RECOGNIZE_SPEECH .

Usage

From source file:com.telepromptu.TeleprompterService.java

private void startListening() {
    if (speechRecognizer == null) {
        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
        speechRecognizer.setRecognitionListener(new DictationListener());
        Intent speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
        speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
        //          speechIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);
        //          speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 300000);
        //          speechIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 300000);
        speechRecognizer.startListening(speechIntent);
    }/*from   ww  w.  j  av  a2s .  c  o  m*/
}

From source file:de.dfki.iui.mmir.plugins.speech.android.AndroidSpeechRecognizer.java

private void _startSpeechRecognitionActivity(JSONArray args, CallbackContext callbackContext,
        boolean isWithEndOfSpeechDetection) {
    int maxMatches = 0;
    String prompt = "";//TODO remove? (not used when ASR is directly used as service here...)
    String language = Locale.getDefault().toString();
    boolean isIntermediate = false;

    try {//from ww w.  j a v a2  s . c  om
        if (args.length() > 0) {
            // Optional language specified
            language = args.getString(0);
        }
        if (args.length() > 1) {
            isIntermediate = args.getBoolean(1);
        }
        if (args.length() > 2) {
            // Maximum number of matches, 0 means that the recognizer "decides"
            String temp = args.getString(2);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 3) {
            // Optional text prompt
            prompt = args.getString(3);
        }

        //TODO if ... withoutEndOfSpeechDetection = ...
    } catch (Exception e) {
        Log.e(PLUGIN_NAME, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    // Create the intent and set parameters
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    if (!isWithEndOfSpeechDetection) {

        // try to simulate start/stop-recording behavior (without end-of-speech detection) 

        //NOTE these setting do not seem to have any effect for default Google Recognizer API level > 16

        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 10000l);

        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, new Long(10000));
        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
                new Long(6 * 1000));
    }

    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);

    if (!prompt.equals(""))
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);

    if (isIntermediate)
        intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

    //NOTE the extra package seems to be required for older Android versions, but not since API level 17(?)
    if (SDK_VERSION <= Build.VERSION_CODES.JELLY_BEAN)
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, cordova.getActivity().getPackageName());

    synchronized (speechLock) {

        if (speech != null) {
            speech.destroy();
        }
        speech = SpeechRecognizer.createSpeechRecognizer(cordova.getActivity());

        disableSoundFeedback();

        ++recCounter;
        currentRecognizer = new ASRHandler(recCounter, enableMicLevelsListeners, callbackContext, this);
        currentRecognizer.setHapticPrompt(
                (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE));
        speech.setRecognitionListener(currentRecognizer);
        speech.startListening(intent);

    }
}

From source file:net.olejon.mdapp.NasjonaleRetningslinjerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }//w w  w  . ja va  2  s  .  co  m
    case R.id.nasjonale_retningslinjer_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;
    }
    case R.id.nasjonale_retningslinjer_menu_clear_recent_searches: {
        clearRecentSearches();
        return true;
    }
    default: {
        return super.onOptionsItemSelected(item);
    }
    }
}

From source file:net.olejon.mdapp.PoisoningsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }//from  w ww .j  av  a  2 s .  c  om
    case R.id.poisonings_menu_call: {
        try {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+4722591300"));
            startActivity(intent);
        } 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;
    }
    case R.id.poisonings_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;
    }
    case R.id.poisonings_menu_clear_recent_searches: {
        clearRecentSearches();
        return true;
    }
    default: {
        return super.onOptionsItemSelected(item);
    }
    }
}

From source file:com.justplay1.shoppist.features.search.SearchFragment.java

private void startTextToSpeech(String prompt, int requestCode) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    try {//from w w  w.j  a v  a2 s .  c o  m
        startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getContext(), getString(R.string.recognition_not_present), Toast.LENGTH_SHORT).show();
    }
}

From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java

private void speechToText() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());

    try {/*from   w w  w  .ja va2 s. com*/
        if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
            AlfrescoNotificationManager.getInstance(getActivity()).showAlertCrouton(getActivity(),
                    getString(R.string.feature_disable));
            return;
        }
        startActivityForResult(intent, RequestCode.TEXT_TO_SPEECH);
    } catch (ActivityNotFoundException a) {
        AlfrescoNotificationManager.getInstance(getActivity()).showToast(R.string.file_editor_error_speech);
    }
}

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.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java

private void speechToText() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());

    try {/*from   w  w w  .  j  a v a  2  s  .c o m*/
        startActivityForResult(intent, RequestCode.TEXT_TO_SPEECH);
    } catch (ActivityNotFoundException a) {
        // Error

    }
}

From source file:com.pixplicity.castdemo.MainActivity.java

/**
 * Android voice recognition/* ww  w  .j  a  va2s .  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);
}