TextToSpeech has a way to set the speech rate: setSpeechRate(). But it doesn't have an opposite method of querying the current speed.
Is there a way to query the system for that value?
TextToSpeech has a way to set the speech rate: setSpeechRate(). But it doesn't have an opposite method of querying the current speed.
Is there a way to query the system for that value?
You may get default TTS speech rate
Settings.Secure.getInt(getContentResolver(), Settings.Secure.TTS_DEFAULT_RATE, 100) / 100f;
I was looking for similar thing and it seems like there really isn't such a method. But since 1.0 is the normal speech rate, I solved it by keeping the rate in my own variable. I have a class that provides few methods to work with TTS, so here's my implementation:
public class MyTts {
private static float rate = 1.0f;
...
public float getSpeechRate() {
return rate;
}
public int setSpeechRate(float rt) {
rate = rt;
return tts.setSpeechRate(rate);
}
...
}
Where setSpeechRate
returns TextToSpeech.ERROR
or TextToSpeech.SUCCESS
according to documentation.
Edit: Seems like when I set rate to i.e. 1.5f and then back to 1.0f it's not the same. It depends on tts settings in Android.