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

前端 未结 2 682
青春惊慌失措
青春惊慌失措 2021-01-18 17:47

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

2条回答
  •  无人共我
    2021-01-18 17:58

    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.

提交回复
热议问题