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

前端 未结 2 681
青春惊慌失措
青春惊慌失措 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.

    0 讨论(0)
  • 2021-01-18 18:01

    You may get default TTS speech rate

    Settings.Secure.getInt(getContentResolver(), Settings.Secure.TTS_DEFAULT_RATE, 100) / 100f;
    
    0 讨论(0)
提交回复
热议问题