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.ola.insta.BookingAcivity.java

/**
 * Showing google speech input dialog/*from w  ww  . j  av  a 2 s  . c  o  m*/
 * */
private void promptSpeechInput() {
    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, getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(), getString(R.string.speech_not_supported), Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:com.google.developers.actions.debugger.MainActivity.java

public void voiceSearch(View view) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    // Specify the calling package to identify your application
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());

    // Display an hint to the user about what he should say.
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.try_play_dual_core));

    // Given an hint to the recognizer about what the user is going to say
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    startActivityForResult(intent, RECOGNIZER_REQ_CODE);
}

From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java

/**
 * start broadcast speech to text. Result process in StartScreen
 *///from   w  w  w .j  a va2s  .c om
private void promptSpeechInput(Locale locale) {
    try {
        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.getLanguage());
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, LanguageWork.GetResourceString(context, "say"));
        getActivity().startActivityForResult(intent, 200);
    } catch (ActivityNotFoundException a) {
        Logs.SaveLog(context, a);
        Toast.makeText(context, LanguageWork.GetResourceString(context, "forbidden_option"), Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:com.glabs.homegenie.util.VoiceControl.java

public void startListen() {
    _recognizer = getSpeechRecognizer();
    _recognizer.setRecognitionListener(this);
    ///*from   w w w . j  a  v a 2s .  c  o m*/
    //speech recognition is supported - detect user button clicks
    //start the speech recognition intent passing required data
    Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //indicate package
    //recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    //message to display while listening
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Your wish is my command!");
    //set speech model
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    //specify number of results to retrieve
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
    //start listening
    //startActivityForResult(listenIntent, VR_REQUEST);
    //startActivityForResult(recognizerIntent, VR_REQUEST);
    _recognizer.startListening(recognizerIntent);
}

From source file:com.surveyorexpert.TalkToMe.java

private void sendRecognizeIntent() {
    // Intent //from  w  w w.j ava 2 s .c  om
    intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Press when complete");
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
    startActivityForResult(intent, SPEECH_REQUEST_CODE);
    //   Toast.makeText(getBaseContext(),"TalkToMe Done" , Toast.LENGTH_LONG).show();      
}

From source file:me.tylerbwong.pokebase.gui.fragments.PokebaseFragment.java

@Override
public void onButtonClicked(int buttonCode) {
    if (buttonCode == MaterialSearchBar.BUTTON_SPEECH) {
        Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.speech_prompt));
        startActivityForResult(voiceIntent, RECOGNIZER_REQ_CODE);
    }//from  w  ww . ja  va 2  s.  c  o  m
}

From source file:org.apache.cordova.nodialogspeechrecognizer.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 *
 * @param args/*from  w  ww  . j av  a 2s.  co  m*/
 *          Argument array with the following string args: [req code][number
 *          of matches][prompt string]
 */
private void startSpeechRecognitionActivity(JSONArray args) {
    int maxMatches = 1;
    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
    final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, cordova.getActivity().getPackageName());
    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);
    try {
        Handler loopHandler = new Handler(Looper.getMainLooper());
        loopHandler.post(new Runnable() {

            @Override
            public void run() {
                speech.startListening(intent);
            }

        });
    } catch (Exception e) {
        Log.e("error", "er", e);
    }
    // cordova.startActivityForResult(this, intent, REQUEST_CODE);
}

From source file:com.todoroo.astrid.voice.VoiceInputAssistant.java

/**
 * Fire an intent to start the speech recognition activity.
 * This is fired by the listener on the microphone-button.
 *
 * @param prompt Specify the R.string.string_id resource for the prompt-text during voice-recognition here
 *//*from w ww. j  a  v  a  2s. c o  m*/
public void startVoiceRecognitionActivity(Fragment fragment, int prompt) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, ContextManager.getContext().getString(prompt));
    String detailMessage = "Error! No Fragment or Activity was registered to handle this voiceinput-request!";
    if (activity != null)
        activity.startActivityForResult(intent, requestCode);
    else if (fragment != null)
        fragment.startActivityForResult(intent, requestCode);
    else
        Log.e("Astrid VoiceInputAssistant", detailMessage, new IllegalStateException(detailMessage));
}

From source file:com.example.h156252.connected_cars.CarGrid.java

/**
 * Showing google speech input dialog//w  w  w. ja  va 2s  . com
 * */
private void promptSpeechInput() {
    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, "Whats your message?!");
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(), "Speech not supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.jaspersoft.android.jaspermobile.activities.library.LibraryPageFragment.java

private void initVoiceRecognition() {
    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.voice_command_title));
    startActivityForResult(intent, VOICE_COMMAND);
    analytics.sendEvent(Analytics.EventCategory.CATALOG.getValue(), Analytics.EventAction.CLICKED.getValue(),
            Analytics.EventLabel.VOICE_COMMANDS.getValue());
}