Example usage for android.speech RecognizerIntent ACTION_RECOGNIZE_SPEECH

List of usage examples for android.speech RecognizerIntent ACTION_RECOGNIZE_SPEECH

Introduction

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

Prototype

String ACTION_RECOGNIZE_SPEECH

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

Click Source Link

Document

Starts an activity that will prompt the user for speech and send it through a speech recognizer.

Usage

From source file:Main.java

public static boolean hasSpeechToText(Context context) {
    try {//from w  w  w .j  a va2  s  .c  o m
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());
        return intent.resolveActivity(context.getPackageManager()) != null;
    } catch (Exception e) {
        return false;
    }
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0) {
        findViewById(R.id.imageButton).setEnabled(false);
        Toast.makeText(this, "Speech Recognition Not Supported", Toast.LENGTH_LONG).show();
    }/*  w  w w. j  ava 2 s  .  c  o  m*/

    SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
}

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

/**
 * Call this to see if your phone supports voiceinput in its current configuration.
 * If this method returns false, it could also mean that Google Voicesearch is simply
 * not installed./*from w ww. j  a  v  a  2s.  co m*/
 * If this method returns true, internal use of it enables the registered microphone-button.
 *
 * @return whether this phone supports voiceinput
 */
public static boolean voiceInputAvailable(Context context) {
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    return (activities.size() != 0);
}

From source file:MainActivity.java

public void speakNow(View view) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    startActivityForResult(intent, REQUEST_SPEECH);
}

From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java

public static void manageVisibiltyFieldSpeech(Context context, ImageButton button, AutoCompleteTextView text,
        int idRightof, int idLeftOf, int idBelow) {
    // Manage speech button just if package present on device
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0) {
        button.setVisibility(View.GONE);

        if ((text != null) && (Integer.valueOf(Build.VERSION.SDK) <= 3)) {
            // Manage specificity for version before 4
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT);
            if (idRightof != -1) {
                params.addRule(RelativeLayout.RIGHT_OF, idRightof);
            }//from w  w w. j  a v a 2 s. c o m
            if (idLeftOf != -1) {
                params.addRule(RelativeLayout.LEFT_OF, idLeftOf);
            }
            if (idBelow != -1) {
                params.addRule(RelativeLayout.BELOW, idBelow);
            }
            text.setSingleLine(true);
            text.setLayoutParams(params);
        }
    }
}

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

private static boolean isSpeechRecognitionActivityPresented(Activity callerActivity) {
    try {// w  ww. ja v  a2s.c  o  m
        PackageManager pm = callerActivity.getPackageManager();
        List<ResolveInfo> activities = pm
                .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        if (activities.size() != 0) {
            return true;
        }
    } catch (Exception e) {
        L.bug(e);
    }
    return false;
}

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;
            }//  w  w  w .  ja  va 2  s  .co 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.ipo.wiimote.SpeechRecognizer.java

/**
 * Checks if a recognizer is present on this device
 *///from  w  w  w  . j  av  a 2s . c  o m
private boolean IsSpeechRecognizerPresent() {
    PackageManager pm = cordova.getActivity().getPackageManager();
    List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    return !activities.isEmpty();
}

From source file:com.hollowsoft.smarthome.view.MainScreen.java

public void onSpeak(final View view) {
    ///*from w  ww . j  a  v  a 2  s.c o  m*/
    // final SpeechRecognizer recognizer =
    // SpeechRecognizer.createSpeechRecognizer(this);
    //
    // final Intent intent = new
    // Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //
    // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "pt-BR");
    //
    // recognizer.startListening(intent);
    //
    // recognizer.setRecognitionListener(this);
    final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "pt-BR");
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    startActivityForResult(intent, 1337);
}