onRangeStart() stops getting callbacks while reading a paragraph (after encountering a punctuation)

Viewed 224

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?

1 Answers

The implementation/behavior of onRangeStart() is going depend on the engine installed on the device you're using to test.

So either you were testing on two completely different engines, one of which has a less than desirable implementation, OR

The engine you were testing successfully was updated between your tests, and an actual bug was introduced in the update.

You can use the following method to determine the engine you're using during a test:

private ArrayList<String> whatEnginesAreInstalled(Context context) {
    final Intent ttsIntent = new Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent, PackageManager.GET_META_DATA);
    ArrayList<String> installedEngineNames = new ArrayList<>();
    for (ResolveInfo r : list) {
        String engineName = r.activityInfo.applicationInfo.packageName;
        installedEngineNames.add(engineName);

        // just logging the version number out of interest
        String version = "null";
        try {
            version = pm.getPackageInfo(engineName,
            PackageManager.GET_META_DATA).versionName;
            } catch (Exception e) {
                Log.i("XXX", "try catch error");
            }
        Log.i("XXX", "we found an engine: " + engineName);
        Log.i("XXX", "version: " + version);
    }
    return installedEngineNames;
}
Related