Android SpeechRecognizer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SpeechRecognizer class.

This code example shows how to use the following methods:setRecognitionListener, startListening
     * @param callingPackage e.g. com.myapp.example 
     * @param speakNowMessage e.g. "Speak now!" 
     * @param processingMessage e.g. "Processing..." 
     */ 
    public void start(String callingPackage, String speakNowMessage, String processingMessage) {
        sr.setRecognitionListener(this);
 
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, callingPackage);
 
        speechStarted = 0;
        baos.reset();
 
        speakPd = new ProgressDialog(context);
        speakPd.setMessage(speakNowMessage);
        speakPd.setIndeterminate(true);
        speakPd.setCancelable(true);
        speakPd.setOnCancelListener(new OnCancelListener() {

7
CodeRank
This code example shows how to use the following methods:setRecognitionListener, startListening
        if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
        { 
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
        } 
         
        recognizer.setRecognitionListener(listener);
        recognizer.startListening(recognizerIntent);
    } 
 
    public static String diagnoseErrorCode(int errorCode)
    { 
        String message;
        switch (errorCode)
        { 
            case SpeechRecognizer.ERROR_AUDIO:
                message = "Audio recording error";
                break; 
            case SpeechRecognizer.ERROR_CLIENT:
                message = "Client side error";
                break; 
9
CodeRank
This code example shows how to use the following methods:setRecognitionListener
            // provider, in which case the first available speech recognition provider is used. 
            // Caveat: Continuous mode may not work as expected with a different provider. 
            mRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
        } 
 
        mRecognizer.setRecognitionListener(mListener);
    } 
 
    // This function destroys everything when recognition is done, taking care to properly tear 
    // down by calling On{Sound,Audio}End if corresponding On{Audio,Sound}Start were called. 
    private void terminate(int error) {
 
        if (mState != STATE_IDLE) {
            if (mState == STATE_CAPTURING_SPEECH) {
                nativeOnSoundEnd(mNativeSpeechRecognizerImplAndroid);
            } 
            nativeOnAudioEnd(mNativeSpeechRecognizerImplAndroid);
            mState = STATE_IDLE;
        } 
 
5
CodeRank
This code example shows how to use the following methods:cancel, destroy, stopListening
    } 
     
    @Override 
	protected void onDestroy() { 
    	if (sr != null) {
        	sr.stopListening();
        	sr.cancel();
        	sr.destroy();
        } 
    	super.onDestroy(); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:startListening
 
      @Override 
      public void onError(int error) { 
         if (error == SpeechRecognizer.ERROR_NO_MATCH || 
          error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) { 
            mSpeechRecognizer.startListening(mRecognizerIntent); 
         } else { 
            Log.e("SpeechCommander", "onError: " + error); 
            restartSpeech(DEFAULT_RESTART_TIME); 
         } 
      } 
 
      @Override 
      public void onResults(Bundle results) { 
         ArrayList<String> matches = results.getStringArrayList( 
          SpeechRecognizer.RESULTS_RECOGNITION); 
         int depth = Math.min(mDepth, matches.size()); 
         Command command; 
 
         Log.d("SpeechCommander", "Results: " + matches); 
5
CodeRank
This code example shows how to use the following methods:destroy, stopListening
    } 
 
    @Override 
    protected void onDestroy() { 
        super.onDestroy(); 
        sr.stopListening();
        sr.destroy();
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:setRecognitionListener, startListening
                // TODO(satish): Show an error UI here. 
                Log.e("ChromeView", "Could not get speech recognizer.");
                nativeDidCompleteRecognition(sessionId);
                return; 
            } 
            mRecognizer.setRecognitionListener(this);
        } 
 
        mSessionId = sessionId;
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, grammar);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                        "org.chromium.content.browser"); 
        // TODO(satish): Change this hardcoded value to a parameter once 
        // maxresults is implemented as an attribute in webkit. 
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
        mRecognizer.startListening(intent);
 
        // TODO(satish): Add a UI to indicate that recognition is in progress 

4
CodeRank
This code example shows how to use the following methods:setRecognitionListener, startListening
        if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
        { 
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
        } 
         
        recognizer.setRecognitionListener(listener);
        recognizer.startListening(recognizerIntent);
    } 
 
    public static String diagnoseErrorCode(int errorCode)
    { 
        String message;
        switch (errorCode)
        { 
            case SpeechRecognizer.ERROR_AUDIO:
                message = "Audio recording error";
                break; 
            case SpeechRecognizer.ERROR_CLIENT:
                message = "Client side error";
                break; 
4
CodeRank
This code example shows how to use the following methods:setRecognitionListener, startListening
	private TextToSpeech tts;
	private boolean wait_c;
	public void checkVoiceRecognition() { 
		  // Check if voice recognition is present 
		sr = SpeechRecognizer.createSpeechRecognizer(this);
		sr.setRecognitionListener(new listener());  
		 if (sr == null) {
		   present = false;
		 } 
	 } 
	 
 
	   class listener implements RecognitionListener          
	   { 
	            private static final String TAG = "SR";
				public void onReadyForSpeech(Bundle params)
	            { 
	                     Log.d(TAG, "onReadyForSpeech");
	             		 
	            } 

4
CodeRank
This code example shows how to use the following methods:setRecognitionListener, startListening
 
		System.out.println("Termino de hablar de hablar!");
		if (atento) {
			sr = SpeechRecognizer.createSpeechRecognizer(contexto);
			listener = new MyRL();
			sr.setRecognitionListener(listener);
			Intent algo = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
			algo.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
			algo.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "es-ES");
			algo.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
			sr.startListening(algo);
			atento = false;
		} 
		else 
			System.out.println("Y a mi que me importa");
 
	} 
 
	public void probar() { 
 
4
CodeRank

Related Android SpeechRecognizer Questions & Answers:

See Code Examples for Android SpeechRecognizer Methods: