public static float[] getFloatArrayExtra(Intent intent, String name) { if (intent != null || !hasExtra(intent, name)) return null; return intent.getFloatArrayExtra(name); }
/** * in your Activity */ public void startVoice(View view) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Go on, say something..."); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(intent, 111); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 111) { if (resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); float [] scores = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES); // TODO: loop through possible matches, // and choose what you think is appropriate } } }
public static float[] getFloatArrayExtra(Intent intent, String name) { if (!hasIntent(intent) || !hasExtra(intent, name)) return null; return intent.getFloatArrayExtra(name); }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TTS_DATA_CHECK) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { ttsIsInit = true; if (tts.isLanguageAvailable(Locale.UK) >= 0) tts.setLanguage(Locale.UK); tts.setPitch(0.8f); tts.setSpeechRate(1.1f); speak(); } } }); } else { Intent installVoice = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installVoice); } } // Listing 14-3: Finding the results of a speech recognition request if (requestCode == VOICE_RECOGNITION && resultCode == RESULT_OK) { ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); float[] confidence = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES); // TODO Do something with the recognized voice strings } }
return checkNull(intent.getByteArrayExtra(key), defValue); } else if ("float[]".equals(type)) { return checkNull(intent.getFloatArrayExtra(key), defValue); } else if ("String[]".equals(type)) { return checkNull(intent.getStringArrayExtra(key), defValue);
getWindow().setSharedElementsUseOverlay(true); final float[] buttonLocation = getIntent().getFloatArrayExtra(EXTRA_REVEAL_ANIM_LOCATION); final float x = buttonLocation[0]; final float y = buttonLocation[1];