I am trying to use Android Text to Speech functionality to read text in a document and highlight the words while reading aloud. I have set up an utterance progress listener using setOnUtteranceProgressListener() on my TTS object and overridden functions like onStart(), onDone() and onRangeStart() in it. The expectation is that while my text is being read aloud, onRangeStart(String utteranceId, int start, int end, int frame) will give me callbacks when TTS service is about to speak the specified range of the utterance with the given utteranceId.
Here is the documentation for the same: https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onRangeStart(java.lang.String,%20int,%20int,%20int)
The documents that I am trying to read consists of multiple paragraphs and each paragraph can have multiple sentences. For example: This is how a sample paragraph looks like:
Hello word, how are you? I want an opportunity to discuss more about it. Let me know what you think.
The expectation is that for each of the words in the string, I should get events in onRangeStart() but it is not happening. What I am getting now is:
onRangeStart utteranceId: 100000, start: 0, end: 5, frame: 120, text: Hello
onRangeStart utteranceId: 100000, start: 6, end: 11, frame: 6060, text: world
onRangeStart utteranceId: 100000, start: 13, end: 16, frame: 18720, text: how
onRangeStart utteranceId: 100000, start: 17, end: 20, frame: 23760, text: are
onRangeStart utteranceId: 100000, start: 21, end: 24, frame: 26040, text: you
and after this, there are no more callbacks in onRangeStart(). What I am unable to understand is that it was working fine around 2 weeks back and I was continuously testing the app but it suddenly stopped working. I have also checked the documentation of TextToSpeech, UtteranceProgressListener, etc. but there no change has been documented recently.
Can someone help me figure out what is causing this issue?