getSpeechRate()? (or how to tell what rate TTS is currently set at)

拥有回忆 提交于 2019-12-19 19:43:54

问题


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?


回答1:


You may get default TTS speech rate

Settings.Secure.getInt(getContentResolver(), Settings.Secure.TTS_DEFAULT_RATE, 100) / 100f;



回答2:


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.



来源:https://stackoverflow.com/questions/11954874/getspeechrate-or-how-to-tell-what-rate-tts-is-currently-set-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!