How to use the voice command API in Android

I am new to android and am currently working on a small application that runs in the Voice Command API. For example, if I say bluetooth, it will switch the bluetooth phone to the ON / OFF mode (vice versa).

Please help me do this ....

Thanks at Anvance ...

+7
source share
2 answers

Rather simple to use:

private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); //uses free form text input intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); //Puts a customized message to the prompt intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.listenprompt)); startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); } /** * Handles the results from the recognition activity. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { // Fill the list view with the strings the recognizer thought it could have heard ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); //Turn on or off bluetooth here } else { super.onActivityResult(requestCode, resultCode, data); } } 

And then call startVoiceRecognitionActivity() from your code where you need it. Of course you need to have internet access

 <uses-permission android:name="android.permission.INTERNET"></uses-permission> 

in your Android.manifest.

+9
source

Never used it, but the link to android docs seems to describe the main ideas. EDIT: The previous link is currently broken, but this is in the Android Developers Link

+1
source

All Articles