I have an Android TV app, running on a Fire TV Stick. I have initialized a TextToSpeech
engine and I am calling it via the speak
function. My problem is that the speech rate (talk back speed) does not change when I change those in settings. I know that I am able to set the speech rate to a float of my liking using setSpeechRate(rate)
, but I would like to know how to get the rate from the system.
I have so far tried to use:
Settings.Secure.getString(contentResolver, Settings.Secure.TTS_DEFAULT_RATE);
which returns null
, and Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_RATE);
which throws a SettingNotFound
error. If I give it a fallback value, it will just always use that no matter how I change the system VoiceView settings. My code roughly does the following:
TextToSpeech engine = new TextToSpeech(context, this);
ContentResolver contentResolver = context.getContentResolver();
int speechRate = Settings.Secure.getInt(contentResolver, Settings.Secure.TTS_DEFAULT_RATE, 100);
engine.setSpeechRate((float)(speechRate / 100));
engine.speak("This is a sample sentence", QUEUE_FLUSH, null, utteranceID);
I am hesitant to write to the settings, because 1) I don't want to require extra write permissions; 2) Even if I write to it, it seems that changing the system settings will not change this setting, which is my end goal.
Is there some other way to get accessibility settings like VoiceView speed in Android?