Muting the Google voice recognition beep sound

2019-01-26 09:41发布

问题:

I have a test app that uses Google voice in a continuous manner and it plays the beep sound every time Google recognition service is called. I am trying to get rid of the beep sound. I have read threads of muting the music stream but that would not work for me.

I am trying to find the beep file location so I could just go and delete it from the system. I followed this thread, but I cannot see the file in 5.0 system file.

回答1:

Assuming you don't want to mute all streams because you are interested in playing your own sound, this might be a solution for you: Use the Audio Focus API.

So you would have something like this:

AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
...
// Request audio focus for playback
int result = am.requestAudioFocus(afChangeListener,
                             // Use the music stream.
                             AudioManager.STREAM_MUSIC,
                             // Request permanent focus.
                             AudioManager.AUDIOFOCUS_GAIN);

if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
am.registerMediaButtonEventReceiver(RemoteControlReceiver);
// Play your own sound (or play silence)
}
am.abandonAudioFocus(afChangeListener);

I have not tested, whether the Google App (which plays the beep sound) adheres to this request, but generally it should work and its worth giving it a try.

Another option would be to directly mute all sounds coming from the Google App (which includes the Google voice recognition beep sound). The advantage of this method is that there is no interference with any other streaming audio. The following is a link for further detail. Do note, however, that this requires root access: https://android.stackexchange.com/questions/128588/how-do-i-disable-the-google-voice-typing-voice-search-ding-sound.



回答2:

The only solution I've found to mute beep sound recognition is:

audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

Before you should save the volume, for example:

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
current_volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

To return to restore the volume level, such as tapeworms:

audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
            AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

I hope it helps you on something



回答3:

You can use audio manager to control the sounds

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

before you start recognizing call

 audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);

and after recognition is complete call

audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);


回答4:

I found another solution witch works fine for me. I set the audio stream of the media player to another stream, so i could mute the music stream. I hope that helps somebody else too.

afd = context.getResources().openRawResourceFd(R.raw.duduuudududu2);

mp.reset();
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
myAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,0,0);

try 
{
   mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
   mp.prepare();
} 
catch (IOException e) 
{
   e.printStackTrace();
}

mp.start();