getSpeechRate()?(或如何知道当前设置的TTS速率)

an0*_*00b 5 android text-to-speech

TextToSpeech有一种设置语音速率的方法:setSpeechRate()。但是它没有查询当前速度的相反方法。

有没有办法向系统查询值?

Mic*_*cer 0

我一直在寻找类似的东西,似乎确实没有这样的方法。但由于1.0 是正常的语速,我通过将语速保留在我自己的变量中来解决这个问题。我有一个类提供了一些使用 TTS 的方法,所以这是我的实现:

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);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

哪里setSpeechRate退货TextToSpeech.ERRORTextToSpeech.SUCCESS根据文件。

编辑:似乎当我将速率设置为 ie 1.5f 然后再设置回 1.0f 时,它是不一样的。这取决于 Android 中的 tts 设置。