Example usage for android.speech RecognizerIntent EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS

List of usage examples for android.speech RecognizerIntent EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS

Introduction

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

Prototype

String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS

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

Click Source Link

Document

The minimum length of an utterance.

Usage

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.TextLineWidget.java

@Override
public void initializeWidget() {
    mEditText = (EditText) findViewById(R.id.edit_text);
    if (mColorScheme == BrandingMgr.ColorScheme.DARK) {
        UIUtils.setColors(ContextCompat.getColor(mActivity, R.color.mc_white), mEditText);
    } else {//w w  w .j av  a2  s. c o  m
        UIUtils.setColors(mActivity, mEditText);
    }
    mEditText.setTextColor(mTextColor);
    mEditText.setText((String) mWidgetMap.get("value"));
    mEditText.setHint((String) mWidgetMap.get("place_holder"));
    mEditText.setFilters(new InputFilter[] {
            new InputFilter.LengthFilter(((Long) mWidgetMap.get("max_chars")).intValue()) });
    mEditText.setInputType(
            getDefaultInputTypes() | KeyboardType.getInputType((String) mWidgetMap.get("keyboard_type")));

    ImageButton btnSpeak = (ImageButton) findViewById(R.id.btn_speak);
    if (AppConstants.SPEECH_TO_TEXT && isSpeechRecognitionActivityPresented(mActivity)) {
        IconicsDrawable icon = new IconicsDrawable(mActivity, FontAwesome.Icon.faw_microphone)
                .color(LookAndFeelConstants.getPrimaryIconColor(mActivity)).sizeDp(20);
        btnSpeak.setVisibility(View.VISIBLE);
        btnSpeak.setImageDrawable(icon);
        btnSpeak.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                    voiceIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
                            1500);
                    voiceIntent.putExtra(
                            RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 1500);
                    voiceIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 15000);
                    voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
                    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
                    mActivity.startActivityForResult(voiceIntent, REQUEST_CODE_VOICE);
                } catch (ActivityNotFoundException e) {
                    L.bug(e);
                }
            }
        });
    } else {
        btnSpeak.setVisibility(View.GONE);
    }
}

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

/**
 * create the {@link RecognizerIntent} based on the many preferences
 *//*from w  w w  . ja v a  2  s  .  c  om*/
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.wizardsofm.deskclock.alarms.AlarmActivity.java

void listenForCommand() {

    //        if (speech == null) {
    //            speech = SpeechRecognizer.createSpeechRecognizer(this);
    //            speech.setRecognitionListener(MainActivity.this);
    //        }//from   w  w w .  j  a va  2  s. c  om
    //        speech = SpeechRecognizer.createSpeechRecognizer(this);
    //        speech.setRecognitionListener(this);

    i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");
    //        i.putExtra("android.speech.extra.DICTATION_MODE", true);
    //        i.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
    i.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 5000);
    try {
        startActivityForResult(i, 100);

        new CountDownTimer(5000, 1000) {

            public void onTick(long millisUntilFinished) {
                //do nothing, just let it tick
            }

            public void onFinish() {
                if (!alarmStopped) {
                    listenForCommand();
                }
            }
        }.start();

        //            speech.startListening(i);
    } catch (Exception e) {

    }
}