private void updateLanguagePreference(String language) { TextView textView = (TextView) findViewById(R.id.language_preference); textView.setText(language); }
/** * Handle the click on the start recognition button. */ public void onClick(View v) { if (v.getId() == R.id.btn_speak) { startVoiceRecognitionActivity(); } }
/** * Called with the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); // Inflate our UI from its XML layout description. setContentView(R.layout.voice_recognition); // Get display items for later interaction Button speakButton = (Button) findViewById(R.id.btn_speak); mList = (ListView) findViewById(R.id.list); mSupportedLanguageView = (Spinner) findViewById(R.id.supported_languages); // Check to see if a recognition activity is present PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { speakButton.setOnClickListener(this); } else { speakButton.setEnabled(false); speakButton.setText("Recognizer not present"); } // Most of the applications do not have to handle the voice settings. If the application // does not require a recognition in a specific language (i.e., different from the system // locale), the application does not need to read the voice settings. refreshVoiceSettings(); }
private void refreshVoiceSettings() { Log.i(TAG, "Sending broadcast"); sendOrderedBroadcast(RecognizerIntent.getVoiceDetailsIntent(this), null, new SupportedLanguageBroadcastReceiver(), null, Activity.RESULT_OK, null, null); }
/** * Fire an intent to start the speech recognition activity. */ private void startVoiceRecognitionActivity() { 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, "Speech recognition demo"); // 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); // Specify how many results you want to receive. The results will be sorted // where the first result is the one with higher confidence. intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); // Specify the recognition language. This parameter has to be specified only if the // recognition has to be done in a specific language and not the default one (i.e., the // system locale). Most of the applications do not have to set this parameter. if (!mSupportedLanguageView.getSelectedItem().toString().equals("Default")) { intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, mSupportedLanguageView.getSelectedItem().toString()); } startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); }
/** * Called with the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); // Inflate our UI from its XML layout description. setContentView(R.layout.voice_recognition); // Get display items for later interaction Button speakButton = (Button) findViewById(R.id.btn_speak); mList = (ListView) findViewById(R.id.list); mSupportedLanguageView = (Spinner) findViewById(R.id.supported_languages); // Check to see if a recognition activity is present PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { speakButton.setOnClickListener(this); } else { speakButton.setEnabled(false); speakButton.setText("Recognizer not present"); } // Most of the applications do not have to handle the voice settings. If the application // does not require a recognition in a specific language (i.e., different from the system // locale), the application does not need to read the voice settings. refreshVoiceSettings(); }
private void refreshVoiceSettings() { Log.i(TAG, "Sending broadcast"); sendOrderedBroadcast(RecognizerIntent.getVoiceDetailsIntent(this), null, new SupportedLanguageBroadcastReceiver(), null, Activity.RESULT_OK, null, null); }
/** * Fire an intent to start the speech recognition activity. */ private void startVoiceRecognitionActivity() { 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, "Speech recognition demo"); // 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); // Specify how many results you want to receive. The results will be sorted // where the first result is the one with higher confidence. intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); // Specify the recognition language. This parameter has to be specified only if the // recognition has to be done in a specific language and not the default one (i.e., the // system locale). Most of the applications do not have to set this parameter. if (!mSupportedLanguageView.getSelectedItem().toString().equals("Default")) { intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, mSupportedLanguageView.getSelectedItem().toString()); } startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); }
/** * Handle the click on the start recognition button. */ public void onClick(View v) { if (v.getId() == R.id.btn_speak) { startVoiceRecognitionActivity(); } }
private void updateLanguagePreference(String language) { TextView textView = (TextView) findViewById(R.id.language_preference); textView.setText(language); }