How to turn off the beep for SpeechRecognizer?

This was asked before, but no one seemed to have a solution: Mect SpeechRecognizer Beep Sound

However, I would still like to know if anyone knows how to turn off the beep for SpeechRecognizer?

I am creating a speech recognition object: private SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer (this);

And then in my class I create a speech reconnaissance similar to 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 good ideas? I researched that I could create an AudioManager object (AudioManager mAudioManager), and then using setStreamSolo () I could mute the sound. But I'm not sure how to implement this. I added it to my instance code for the speech recognizer, and nothing happened. Is this something I should call from my main class?

 mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true); 

Thanks in advance.

+6
android voice-recognition audio
source share
2 answers

I would comment, but I have no representative. However, I would like to help.

Did you see that:

Continues speech recognition beep after updating Google Search

Is it possible to disable silent mode programmatically in android?

Disable global sound in Android

It seems to me that the code differs depending on the version of Android - as indicated in the first link, Google switched the output of the "sound signal" to the media stream .

I assume that one of these issues will have a solution. If so, please write what you did as you stated that many people have a problem.

My suggestion:

 //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 assume this answer from users of Witness apps will work. Credit: @WitnessApplications

In addition, the scope will be prior to launch (i);

+13
source share

With the solution above from Mark you will have a failure with the following description:

 Failure delivering result ResultInfo{ who=@android :requestPermissions:, request=65736, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity java.lang.SecurityException: Not allowed to change Do Not Disturb state 

If you just want to turn off the beep for the speech recognizer, you just need to turn off AudioManager.STREAM_MUSIC .

In Kotlin, for me it looks like this:

 object AudioUtils { @JvmStatic fun muteAudio(shouldMute: Boolean, context: Context) { val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager val muteValue = if (shouldMute) AudioManager.ADJUST_MUTE else AudioManager.ADJUST_UNMUTE audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, muteValue, 0) } } 
+1
source share

All Articles