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.
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.
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
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);
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();
Related
This question already has answers here:
Inject audio into voice stream in android
(2 answers)
Closed 3 years ago.
I am looking for a way to play an audio message to recipient of a phone call as soon as he/she receives the call. I want to push my audio when someone receives the call and then I start conversation. Example:- When some organization calls they start with a greetings audio message first then start the actual conversation.
I have tried searching a lot but all the questions related to this on Stackoverflow are bit old and they mention that this is not possible. Is it still the case?
Could someone please guide how one could achieve this in android?
You can play and control the audio files in android with the help of the MediaPlayer class.
MediaPlayer: This class is the primary API for playing sound and video.
AudioManager: This class manages audio sources and audio output
Simply you can use MediaPlayer and play the audio file. Check out this nice example for playing Audio. How to play audio in android..
public void audioPlayer(String path, String fileName){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(path + File.separator + fileName);
mp.prepare();
mp.start();
} catch (Exception e) {
e.printStackTrace();
}
}
Is there a way we can check programmatically Which Music player is playing right now?
like Google Play, Samsung default Music Player, any 3rd party music player
Actually, we need to programmatically handle play/pause of music player. Google Play and Samsung Music works differently with code :
// Google Play do not play pause with this code
// it is using different package name i guess
CmdStop = "togglepause";
i = new Intent("com.android.music.musicservicecommand.togglepause");
i.putExtra(CmdName, CmdStop);
context.sendBroadcast(i);
Any help is appriciated
Thank you
you don't need a broadcast receiver for this - AudioManager is your friend:
AudioManager.isMusicActive() does the job you want, have a closer look here for details: AudioManager
AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
if(manager.isMusicActive())
{
// do something - or do it not
}
stackoverflow answer
I have an app that keeps on listening to voice and converting it to commands using Google Voice API.
I have been using setStreamMute(AudioManager.STREAM_SYSTEM, true) to mute the beep and it worked until a couple of days ago before "Google Search" new update.
Is there any workaround fix for it?
I know I can use setRingerMode(AudioManager.RINGER_MODE_SILENT), but maybe there is another method?
In the update they switched the output of the 'beep' to the media stream.
So you'll need to mute the AudioManager.STREAM_MUSIC
There's an enhancement request about it here
Mute the beep by muting the notification sound:
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE,0)
Make sure to unmute it after you start listening:
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_UNMUTE,0)
Please note that there's a beep sound when the listening stops.
The beep sound can be muted by using AudioManager
AudioManager mAudioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
To unmute sound
AudioManager mAudioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
Also add permission to Manifest.xml
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
I am not able to mute the incoming call ring tone and play my own media file using MediaPlayer class.
So far I have tried the following in my Activity that pops on top of incoming call screen, started using a BroadcastReceiver; Activity shows up but audio doesn't play:
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_RING,true);
am.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
Then I start playing the audio file. The sound plays perfectly in normal mode, so I also set the audio mode to MODE_NORMAL using am.setMode method but no luck.
Is there any way around? I am currently mobile and so I could not post full code. If anyone has done this before, a block of code would be a great help. Moreover, I dug up the documentation for AudioManager class and found setRoute or similar method which looks good but it has been deprecated long ago so I didn't want to implement it.
Does this approach have different reaults when screen is on or off during an incoming call?
Can anyone please show me how and where can I modify the Phonegap source to play audio through the earpiece?
Try this code:
private AudioManager m_amAudioManager;
m_amAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_IN_CALL);
m_amAudioManager.setSpeakerphoneOn(false);
Also need to add new permission:
MODIFY_AUDIO_SETTINGS
Either put this code in your activity start (onCreate()) or you need to write a plugin to enable/disable it based on your requirement from the javascript.
Check this post for more
Android - Getting audio to play through earpiece