1

I am implementing Text to speech feature for my android application. I know Text to Speech will user STREAM_MUSIC as default stream. When i invoke Text to Speech it is speaking with expected volume. But i am wondering, when i invoke Text to Speech if there is any ongoing calls in device will result my Speech with low volume. I am not understanding how it is happening. Phone call will user AudioManager.STREAM_VOICE_CALL. Will it effect AudioManager.STREAM_MUSIC volume?

I want to play my speech with default volume even if there is any ongoing call in phone.

Please any one can guide me to understand these AudioManager streams which will effect by which and how.

Here is my text to speech invoking method

 private void speakMessage(String audibleString){
            tTts.speak(audibleString, TextToSpeech.QUEUE_ADD, null);
    }

Thanks in advance

Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69

1 Answers1

0

What you are experiencing is called audio ducking. It is an operation performed automatically by the OS (or sometimes another app) when another audio source obtains focus (similar to how a view obtains focus). Only one audio source can have focus at a time. When another audio source obtains focus, current audio sources may be ducked (quieted), paused or left alone. You can use the AudioManager to request that STREAM_MUSIC be given focus with requestAudioFocus().

Edit: Additional info on audio focus.

pathfinderelite
  • 3,047
  • 1
  • 27
  • 30
  • thank you for your response. I know about the requestAudioFocus() thing also. Earlier also i suspected as you mentioned in your answer.But actually in my case as soon as i got incoming message i am requesting audio focus for STREAM_MUSIC and triggering TTS. If no active calls every thing is perfect. If any active call is going in my phone if i receive message TTS is triggering but with lower volume. I am not understanding why volume is reducing even i requested for focus also. – Raghu Mudem May 30 '15 at 12:40
  • @RaghuRamiReddy Unfortunately, it is only a focus *request*; you aren't guaranteed that you will actually get focus. You could try to gain [exclusive audio access](http://developer.android.com/reference/android/media/AudioManager.html#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE), but I'm not sure it will work with phone calls. You may want to check the return value of `requestAudioFocus()` to see if you are actually getting focus. – pathfinderelite May 30 '15 at 12:51
  • @ pathfindereliteany Do you have any idea: one stream type focus is effected by requesting other stream focus? Suppose STREAM_MUSIC requested by my application can it be effected by phone call application STREAM_VOICE_CALL request? And my problem is i received big message at the staring point my speech is stared with actual volume but in middle of speech i received phone call. Then speech is not stopped but reduced the volume. And i am not controlling volume for stream music in app.I am using Text to speech engine to speak my message. May that TTS engines handling this audio focus loss. – – Raghu Mudem May 30 '15 at 13:15
  • @RaghuRamiReddy Good question. I'm afraid my knowledge on the issue is lacking. See the [link](http://developer.android.com/training/managing-audio/audio-focus.html) I posted, which should be able to explain things better than I can. – pathfinderelite May 30 '15 at 13:43
  • @ pathfinderelite i figured out problem for my issue. When call is going on the android system will updated the AudioManager getMode() value to MODE_IN_CALL. In this case android system by default reducing all other sounds to make voice communication good. Same case for MODE_IN_COMMUNICATION also. – Raghu Mudem May 30 '15 at 15:39