Code example for SpeechRecognizer

Methods: startListening, stopListening

0
    } 
    private void stopVoiceRecognitionService() { 
    	mSpeaker.stopListening();
    } 
    private void startVoiceRecognitionService() { 
    	mSpeaker.stopListening();
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    	//Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 
 
        // 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");
         
        // Continuous Listening 
        //intent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE); 
 
        //intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); 
         
        // 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, 1);
 
        // 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());
        } 
         
        mSpeaker.startListening(intent);
    } 
 
    /** 
     * Fire an intent to start the speech recognition activity. 
     */