Is there any way to control volume of TTS engine when sending request to TTS engine? Can I able to use AudioManager here?
Thank You.
Is there any way to control volume of TTS engine when sending request to TTS engine? Can I able to use AudioManager here?
Thank You.
Yes, as your question asks, you are able to use AudioManager for TTS audio.
If you want to set volume in your code, you'll want to use the
getStreamVolume()
andsetStreamVolume()
methods.If you want to give the user control over the volume (this may depend on how/when your program sets volume), this question points out that you have to call
setVolumeControlStream()
duringOnCreate()
.EDIT: And no, you cannot control volume within the TTS engine's methods (i.e. the
Speak()
method).you can get this in TTS speak() methods, but only starting from API level 11.
To keep backwards compatibility, you could target the higher api level (with lower min sdk) and use a "@TargetApi(api_level)" decorator along with sdk version check.
speak()
method can now control TTS volumeadded in API level 21
Parameter
KEY_PARAM_VOLUME
, key to specify the speech volume relative to the current stream type volume used when speaking text.Volume is specified as a float ranging from 0 to 1 where 0 is silence, and 1 is the maximum volume (the default behavior).
Try this to control the settings:
int iAlertVolume is a 0% to 100%, user sets this to desired volume.
Actual Volume setting:
am.setStreamVolume(am.STREAM_MUSIC, (iAlertVolume*amStreamMusicMaxVol)/100,0 );
The 0 at the end says don't display the system volume control, set to 1 to see system ctrl