6

I'm at a lost. I want to be able to adjust the speak volume. Whatever I do, I can't increase its volume. How do I make it as loud as that found in the Android settings (as below)?

System Settings -> Voice input and output -> Text-to-Speech settings -> Listen to an example

My code at this moment is:

AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setSpeakerphoneOn(true);
int loudmax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
mAudioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,loudmax, AudioManager.FLAG_PLAY_SOUND);
mTts.speak(name,TextToSpeech.QUEUE_FLUSH, null);
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
mmmmm5
  • 151
  • 1
  • 1
  • 14

2 Answers2

17

Try using AudioManager.STREAM_MUSIC when calling the setStreamVolume(...) method. The example speech is affected by the media volume if I adjust the volume of music playback on my phone so I guess STREAM_MUSIC is what you need.

EDIT: This code works perfectly for me...

AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int amStreamMusicMaxVol = am.getStreamMaxVolume(am.STREAM_MUSIC);
am.setStreamVolume(am.STREAM_MUSIC, amStreamMusicMaxVol, 0);
tts.speak("Hello", TextToSpeech.QUEUE_FLUSH, null);

The max volume for STREAM_MUSIC on my phone is 15 and I've even tested this by replacing amStreamMusicMaxVol in my call to am.setStreamVolume(...) above with the values 3, 6, 9, 12, 15 and the volume of the speech is correctly set.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • "Speak" method isn't affected by AudioManager.Stream_MUSIC – mmmmm5 Sep 26 '11 at 18:04
  • 2
    @mmmmm5: ""Speak" method isn't affected by AudioManager.Stream_MUSIC" Yes it is - at least on my HTC Desire. You must be doing something wrong or it just isn't supported on your device/emulator or you need to use `STREAM_SYSTEM` as slayton suggests. See the code I've added in my edit - it works perfectly and I can set the speech volume anywhere between 0-15. – Squonk Sep 26 '11 at 20:27
  • Thanks. It works. 2 things were preventing me from thinking it wasn't - (1) comparing DMTF tone to speak. DMTF tone is much louder. (2) i was running some other activity which cut off the speak from completing, so it sounded softer – mmmmm5 Sep 27 '11 at 13:39
  • I found a way to make the speak volume very loud and that can be controlled by the device volume buttons. Use setVolumeControlStream(int streamType) – mmmmm5 Sep 27 '11 at 14:51
  • 2
    But how can i disable all sounds so that even other application can't change any volume. i mean how to completely disable AudioManager from other application. @Squonk – Sazzad Hissain Khan Nov 28 '13 at 05:36
  • Documentation link http://developer.android.com/reference/android/media/AudioManager.html – fedmich May 21 '14 at 11:40
3

In your code you are changing the volume of notifications. Is the volume of TTS played at the same volume level as notifications? I suspect it isn't and it probably played at either STREAM_SYSTEM or STREAM_MUSIC Try changing the stream type to one of these:

STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC or STREAM_ALARM
slayton
  • 20,123
  • 10
  • 60
  • 89
  • 1
    I was trying to use AudioManager methods (setStreamVolume, getStreamMaxVolume) to make "speak" method louder. But, the "speak" method isn't affected by AudioManager – mmmmm5 Sep 26 '11 at 18:02