How to set the volume for the "talking" text-to-speech method?

I'm lost. I want to adjust the volume of conversations. Whatever I do, I cannot increase its volume. How to make it as loud as in the Android settings (as shown below)?

System settings โ†’ Voice input and output โ†’ Text to speech settings โ†’ Listen to an example

My code at the moment:

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); 
+5
source share
2 answers

Try using AudioManager.STREAM_MUSIC when calling the setStreamVolume(...) method. In a speech example, the volume of the multimedia affects if I adjust the volume of music on my phone, so I think STREAM_MUSIC is what you need.

EDIT: This code works great 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 maximum volume for STREAM_MUSIC on my phone is 15, and I even checked this by replacing amStreamMusicMaxVol with my call am.setStreamVolume(...) above with values โ€‹โ€‹of 3, 6, 9, 12, 15 and speech volume correctly set.

+15
source

In your code, you change the volume of notifications. Is the TTS volume reproducible at the same volume level as the notifications? I suspect this is not the case, and he probably played either STREAM_SYSTEM or STREAM_MUSIC Try changing the stream type to one of the following:

 STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC or STREAM_ALARM 
+3
source

Source: https://habr.com/ru/post/925033/


All Articles