How to mute the beep sound for SpeechRecognizer?

portfoliobuilder picture portfoliobuilder · Aug 28, 2014 · Viewed 17.2k times · Source

This has been asked before, but no one seemed to have a solution: Muting SpeechRecognizer's beep sound

Nevertheless, I still would like to know if anyone knows how to mute the beeping sound for SpeechRecognizer?

I create speechRecognizer object: private SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);

And then in my class I instantiate the speechRecognizer like this

sr.setRecognitionListener(new listener());
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);             
i.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication()
        .getClass().getName());
i.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 6);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "");
i.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 7000);
sr.startListening(i);

Anyone with any good ideas? I researched that I could create an object of AudioManager (AudioManager mAudioManager) and then using setStreamSolo(), I could mute the sound. But I am not sure how to implement this. I added it to my instantiation code for speechRecognizer and nothing happened. Is this something I should call from my main class?

mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);

Thank you in advance.

Answer

Mark picture Mark · Aug 28, 2014

Aww I would comment but I don't have the rep. However I would like to help.

Have you seen this:

Continues Speech Recognition beep sound after Google Search update

Is it possible to turn off the silent mode programmatically in android?

Mute the global sound in Android

It seems to me that the code is different depending on the android version - as stated in the first link, Google switched the output of the 'beep' to the media stream.

I am guessing one of those questions will have the solution. If so please post what you have done, as you stated many people seem to be having the problem.

My guess would be:

//mute audio

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
             amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
             amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
             amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
             amanager.setStreamMute(AudioManager.STREAM_RING, true);
             amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);


//unmute audio

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);

             amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
             amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
             amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
             amanager.setStreamMute(AudioManager.STREAM_RING, false);
             amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);

I imagine this answer from Witness applications user will work. Credit goes to: @WitnessApplications

Also the scope of this would be before you startListening(i);