Example usage for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM

List of usage examples for android.speech RecognizerIntent LANGUAGE_MODEL_FREE_FORM

Introduction

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

Prototype

String LANGUAGE_MODEL_FREE_FORM

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

Click Source Link

Document

Use a language model based on free-form speech recognition.

Usage

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.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.sunildhaker.watch.heart.ConnectActivity.java

private void displaySpeechRecognizer() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // Start the activity, the intent will be populated with the speech text
    startActivityForResult(intent, SPEECH_REQUEST_CODE);
}

From source file:com.vyasware.vaani.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    returnedText = (TextView) findViewById(R.id.textView1);
    outputText = (TextView) findViewById(R.id.textView2);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);

    progressBar.setVisibility(View.INVISIBLE);
    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
    //                "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override//from   w w w.  java  2  s .c  o  m
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                tts.setLanguage(new Locale("hi_IN"));
                tts.setSpeechRate(0.9f);
            }
        }
    });
    returnedText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, returnedText.getText());
            if (intent.resolveActivity(getPackageManager()) != null)
                startActivity(intent);

        }
    });

    toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setIndeterminate(true);
                speech.startListening(recognizerIntent);
                outputText.setText("");
            } else {
                progressBar.setIndeterminate(false);
                progressBar.setVisibility(View.INVISIBLE);
                speech.stopListening();
            }
        }
    });

}

From source file:de.domjos.schooltools.helper.Helper.java

public static void displaySpeechRecognizer(Activity activity, int req_code) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    activity.startActivityForResult(intent, req_code);
}

From source file:com.github.zagum.speechrecognitionview.sample.MainActivity.java

private void startRecognition() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en");
    speechRecognizer.startListening(intent);
}

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

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

    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:ai.api.unityhelper.RecognitionHelper.java

/**
 *
 * @param lang recognition language/*from www .  java 2s .c om*/
 */
private void startListening(final String lang) {
    if (!recognitionActive) {

        final Intent sttIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

        final String language = lang.replace('-', '_');

        sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
        sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language);

        // WORKAROUND for https://code.google.com/p/android/issues/detail?id=75347
        // TODO Must be removed after fix in Android
        sttIntent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[] {});

        runInUiThread(new Runnable() {
            @Override
            public void run() {
                initializeRecognizer();

                speechRecognizer.startListening(sttIntent);
                recognitionActive = true;
            }
        });

    } else {
        Log.w(TAG, "Trying to start recognition while another recognition active");
    }
}

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

/**
  * Fire an intent to start the speech recognition activity.
  */*www.ja  va2 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
    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.urbtek.phonegap.SpeechRecognizer.java

/**
 * Fire an intent to start the speech recognition activity.
 * /*from www .ja va2  s  .  co m*/
 * @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);
}