Example usage for android.speech RecognizerIntent EXTRA_PROMPT

List of usage examples for android.speech RecognizerIntent EXTRA_PROMPT

Introduction

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

Prototype

String EXTRA_PROMPT

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

Click Source Link

Document

Optional text prompt to show to the user when asking them to speak.

Usage

From source file:com.perm.DoomPlay.SearchVkActivity.java

public static Intent getVoiceIntent() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "voice search");
    return intent;
}

From source file:com.manueldeveloper.SpeechRecognizer.java

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    // Check action
    if (action.equals("recognize")) {
        // Get the reference to the callbacks and parameters
        this.speechRecognizerCallbackContext = callbackContext;
        if (args.length() > 0) {
            if (args.getInt(0) >= 1)
                maxResults = args.getInt(0);
            else {
                callbackContext.error("maxResults argument must to be equal or more than 1");
                return true;
            }/*from w  w w  . ja va  2 s  .c  o  m*/
        }
        if (args.length() > 1)
            promptMessage = args.getString(1);

        // Start the recognition process
        recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults);
        if (promptMessage != null)
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, promptMessage);
        cordova.startActivityForResult(this, recognizerIntent, REQUEST_CODE);

        return true;
    }

    return false;
}

From source file:com.uphyca.android.nagiharae.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  ww .jav a 2 s .c  o m

    FragmentManager manager = getSupportFragmentManager();

    mSocketClientFragment = new SocketClientFragment();
    manager.beginTransaction().add(mSocketClientFragment, "socket").commit();

    findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mSocketClientFragment.connect();
        }
    });

    Fragment f = manager.findFragmentByTag("adk");
    if (f == null) {
        mAdkFragment = new AdkFragment();
        manager.beginTransaction().add(mAdkFragment, "adk").commit();
    } else {
        mAdkFragment = (AdkFragment) f;
    }

    mAdkFragment.setOnAccessoryStateChangedListener(new AdkFragment.OnAccessoryStateChangedListener() {

        @Override
        public void onOpend() {
            Log.d(TAG, "connected");
            mButton.setEnabled(true);
        }

        @Override
        public void onClosed() {
            Log.d(TAG, "not connected");
            mButton.setEnabled(false);
        }
    });

    mAdkFragment.setOnLedStateChangedListener(new AdkFragment.OnLedStateChangedListener() {

        @Override
        public void ledStateChanged(boolean isOn) {
            if (isOn) {
                // ???
                Toast.makeText(MainActivity.this, "??", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(MainActivity.this, "?", Toast.LENGTH_LONG).show();
            }
        }
    });

    mButton = (Button) findViewById(R.id.button);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // ACTION_WEB_SEARCH
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                        RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
                intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "??");
                startActivityForResult(intent, REQUEST_CODE);

            } catch (ActivityNotFoundException e) {
                // ?????????????
                Toast.makeText(MainActivity.this, "ActivityNotFoundException", Toast.LENGTH_LONG).show();
            }
        }
    });
}

From source file:com.theultimatelabs.scale.ScaleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scale);/*from w w  w.j  ava 2s  . c om*/

    Log.v(TAG, "onCreate");

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mSettings = getSharedPreferences(PREFS, 0);

    mUnitsText = mSettings.getString("unitsText", "grams");
    mUnitsRatio = mSettings.getFloat("unitsRatio", (float) 1.0);

    mTts = new TextToSpeech(this, this);

    mUnitsView = (TextView) findViewById(R.id.text_unit);
    mUnitsView.setText(mUnitsText);

    findViewById(R.id.text_unit).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            while (mTts.isSpeaking())
                ;
            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 Units");
            startActivityForResult(intent, 0);

            if (adView != null) {
                adView.loadAd(new AdRequest());
            }

        }
    });

    mWeightTextView = (TextView) findViewById(R.id.text_weight);
    mWeightTextView.setText("00.00");
    /*
     * TextPaint weightTextPaint = mWeightTextView.getPaint(); CharSequence
     * weightText = mWeightTextView.getText(); while (weightText !=
     * TextUtils.ellipsize(weightText, weightTextPaint,
     * getWindowManager().getDefaultDisplay
     * ().getWidth()*2/3,TextUtils.TruncateAt.END)) {
     * weightTextPaint.setTextSize(weightTextPaint.getTextSize() - 1); }
     */

    mWeightTextView.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Zero'd", Toast.LENGTH_LONG).show();
            mZeroGrams = mWeightGrams;
            if (adView != null) {
                adView.loadAd(new AdRequest());
            }
        }
    });
    mWeightTextView.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            mZeroGrams = 0;
            Toast.makeText(getApplicationContext(), "Reset", Toast.LENGTH_LONG).show();
            if (adView != null) {
                adView.loadAd(new AdRequest());
            }
            return true;
        }
    });

    disableAdsText = (TextView) findViewById((R.id.text_disableAds));
    disableAdsText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            new AlertDialog.Builder(ScaleActivity.this).setTitle("Keep Software Free and Open Source")
                    .setMessage("Ads help support further development, but they are OPTIONAL."
                            + " If you choose to disable ads, please consider donating. All dontations"
                            + " go towards purchasing hardware for open source development. "
                            + "Disabling ads or donating will not change the features availble in this app."
                            + " Thank you. rob@theultimatelabs.com")
                    .setPositiveButton("Disable Ads", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            adLayout.removeAllViews();
                            adView.removeAllViews();
                            disableAdsText.setVisibility(View.INVISIBLE);
                            mSettings.edit().putBoolean("ads", false).commit();
                            adView = null;
                        }
                    }).setCancelable(true).setNegativeButton("Keep Ads", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).setNeutralButton("Disable Ads + Donate", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            adLayout.removeAllViews();
                            adView.removeAllViews();
                            disableAdsText.setVisibility(View.INVISIBLE);
                            mSettings.edit().putBoolean("ads", false).commit();
                            adView = null;
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://blog.theultimatelabs.com/p/donate.html")));
                        }
                    }).show();
        }
    });

    TextView aboutText = (TextView) findViewById((R.id.text_about));
    aboutText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), AboutActivity.class));
        }
    });

    /*
     * .setMessage() new AlertDialog.Builder(this) .setMessage(mymessage)
     * .setTitle(title) .setCancelable(true)
     * .setNeutralButton(android.R.string.cancel, new
     * DialogInterface.OnClickListener() { public void
     * onClick(DialogInterface dialog, int whichButton){} }) .show(); }}
     */
    // /

    mDensitiesJson = loadJsonResource(R.raw.densities);
    mVolumesJson = loadJsonResource(R.raw.volumes);
    mWeightsJson = loadJsonResource(R.raw.weights);

    // Initiate a generic request to load it with an ad
    if (mSettings.getBoolean("ads", true)) {
        // Create the adViewj
        adView = new AdView(this, AdSize.SMART_BANNER, "a15089dfb39c5a8");

        // Log.w(TAG, new Integer(R.id.layout_ads).toString());
        adLayout = (LinearLayout) findViewById(R.id.layout_ads);

        // Add the adView to it
        adLayout.addView(adView, 0);
        disableAdsText.setVisibility(View.VISIBLE);
    } else {
        disableAdsText.setVisibility(View.INVISIBLE);
        adView = null;
    }

    Intent intent = getIntent();
    mDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

    findScale();

}

From source file:com.urbtek.phonegap.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 * //from  ww  w .  j  a  v a2  s . c  om
 * @param args Argument array with the following string args: [req code][number of matches][prompt string]
 */
private void startSpeechRecognitionActivity(JSONArray args) {
    int reqCode = 42; //Hitchhiker?
    int maxMatches = 0;
    String prompt = "";

    try {
        if (args.length() > 0) {
            // Request code - passed back to the caller on a successful operation
            String temp = args.getString(0);
            reqCode = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(1);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 2) {
            // Optional text prompt
            prompt = args.getString(2);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (!prompt.isEmpty())
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    ctx.startActivityForResult(this, intent, reqCode);
}

From source file:com.corumgaz.mobilsayac.VoiceRecognizer.VoiceRecognizer.java

/**
  * Fire an intent to start the speech recognition activity.
  */*  www  .  j a  v a 2 s  .c  om*/
  * @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
    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 (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (!prompt.equals(""))
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    cordova.startActivityForResult(this, intent, REQUEST_CODE);
}

From source file:com.ipo.wiimote.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 *
 * @param args Argument array with the following string args: [req code][number of matches][prompt string]
 *///from   w  ww  .  ja va 2  s  . com
private void startSpeechRecognitionActivity(JSONArray args) {
    int reqCode = 42; //Hitchhiker?
    int maxMatches = 0;
    String prompt = "";

    try {
        if (args.length() > 0) {
            // Request code - passed back to the caller on a successful operation
            String temp = args.getString(0);
            reqCode = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(1);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 2) {
            // Optional text prompt
            prompt = args.getString(2);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    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.ENGLISH);
    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (!prompt.equals(""))
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    cordova.startActivityForResult(this, intent, reqCode);
}

From source file:com.example.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 * /*from   w ww.  j  a v a  2 s.com*/
 * @param args Argument array with the following string args: [req code][number of matches][prompt string]
 */
private void startSpeechRecognitionActivity(JSONArray args) {
    int reqCode = 42; //Hitchhiker?
    int maxMatches = 0;
    String prompt = "";

    try {
        if (args.length() > 0) {
            // Request code - passed back to the caller on a successful operation
            String temp = args.getString(0);
            reqCode = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(1);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 2) {
            // Optional text prompt
            prompt = args.getString(2);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (prompt.length() > 0)
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    ctx.startActivityForResult(this, intent, reqCode);
}

From source file:com.ksutopia.bbtalks.plugins.P201SpeechToText.java

/**
  * Fire an intent to start the speech recognition activity.
  *// w w w  .j av  a 2 s .  c  o 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:org.apache.cordova.plugins.speech.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 *
 * @param args Argument array with the following string args: [req code][number of matches][prompt string]
 *//* ww w  .j av  a  2  s . c om*/
private void startSpeechRecognitionActivity(JSONArray args) {
    int reqCode = 42; //Hitchhiker?
    int maxMatches = 0;
    String prompt = "";

    try {
        if (args.length() > 0) {
            // Request code - passed back to the caller on a successful operation
            String temp = args.getString(0);
            reqCode = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(1);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 2) {
            // Optional text prompt
            prompt = args.getString(2);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }

    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.ENGLISH);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "org.apache.cordova.plugins.speech");

    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (!prompt.equals(""))
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);

    Log.d(LOG_TAG, "startActivityForResult");
    cordova.startActivityForResult(this, intent, reqCode);
}