Android TextToSpeech UtteranceProgressListener out of sync after changing SpeedRate

Viewed 77

I'm using Android's TextToSpeech. I am also highlighting text as the words are spoken, I am doing this with the help of UtteranceProgressListener and it's method onRangeStart(String utteranceId, int start, int end, int frame).

The problem is that when the speech rate is changed on my TextToSpeech object, the utterance progress listener does not account for this change and continues to execute onRangeStart at the same rate as the default speech rate.

If I set a speech rate of 0.5f then the onRangeStart method will execute as if the speech rate were 1.0f causing the text to be highlighted out of sync with the spoken words. Maybe this is a bug?

Here is my code:

speaker.setSpeechRate(0.5f);
speaker.setOnUtteranceProgressListener(new UtteranceProgressListener() {
    @Override
    public void onStart(String s) { }
    @Override
    public void onDone(String s) { }
    @Override
    public void onError(String s) { }

    @Override
    public void onRangeStart(String utteranceId, int start, int end, int frame) {
        super.onRangeStart(utteranceId, start, end, frame);
        tarAdapter.highlightWord(currentSentenceIndex, start, end);
    }
});
0 Answers
Related