Code example for SpeechRecognizer

Methods: setRecognitionListenerstartListening

0
    private long speechStarted = 0;
    private SpeechRecognizer sr;
    private ProgressDialog pd;
 
    private void write() { 
        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, "com.domain.app");
 
        speechStarted = 0;
        baos.reset();
 
        pd = new ProgressDialog(this);
        pd.setMessage("Speak now...");
        pd.setIndeterminate(true);
        pd.setCancelable(true);
        pd.setOnCancelListener(new OnCancelListener() {
            @Override 
            public void onCancel(DialogInterface dialog) {
                sr.cancel();
                onEndOfSpeech(); 
            } 
        }); 
 
        pd.show();
        sr.startListening(intent);
 
        speechStarted = System.currentTimeMillis();
    } 
 
    @Override 
Contextual code suggestions in your IDE  Get Codota for Java