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

2019-02-24 03:16发布

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?

2条回答
来,给爷笑一个
2楼-- · 2019-02-24 03:57

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.

查看更多
相关推荐>>
3楼-- · 2019-02-24 03:58

You may get default TTS speech rate

Settings.Secure.getInt(getContentResolver(), Settings.Secure.TTS_DEFAULT_RATE, 100) / 100f;
查看更多
登录 后发表回答