@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        btnRecognize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (recognizing) {
                    handler.stopListening();
                } else {
                    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, getContext().getPackageName());
                    handler.startListening(intent);
                }
                btnRecognize.setEnabled(false);
            }
        });
        handler = DbmHandler.Factory.newSpeechRecognizerHandler(getContext());
        handler.innerRecognitionListener(new SimpleRecognitionListener() {

            @Override
            public void onReadyForSpeech(Bundle params) {
                super.onReadyForSpeech(params);
                onStartRecognizing();
            }

            @Override
            public void onResults(Bundle results) {
                super.onResults(results);
                onStopRecognizing();
            }

            @Override
            public void onError(int error) {
                super.onError(error);
                onStopRecognizing();

            }
        });
        audioVisualization.linkTo(handler);
    }
Fragment with visualization of speech recognition.
app/src/main/java/com/cleveroad/example/SpeechRecognitionFragment.java