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.
speak()
method can now control TTS volume
added in API level 21
int speak (CharSequence text,
int queueMode,
Bundle: KEY_PARAM_VOLUME;...,
String utteranceId)
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).
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 the single word, at a lower volume if possible */
protected void speakOneWord(String text) {
int apiVer = android.os.Build.VERSION.SDK_INT;
if (apiVer >= 11){
speakApi13(text);
} else {
// compatibility mode
HashMap<String, String> params = new HashMap<String, String>();
mTts.speak(text, TextToSpeech.QUEUE_ADD, params);
}
}
/** speak at a lower volume, for platform >= 13 */
@TargetApi(13)
protected void speakApi13(String text) {
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, "0.1");
mTts.speak(text, TextToSpeech.QUEUE_ADD, params);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With