Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextToSpeech.OnInitListener.onInit(int) being called continuously

Tags:

I'm getting reports that, on some (not all) HTC Desire HD (FRF91, 2.2) and HTC EVO 4G ( PC36100|3.29.651.5, 2.2), the TextToSpeech.OnInitListener.onInit(int) is being called repeatedly (over 1500 times in the space of a few seconds) on the same object. This behaviour does not occur for any of my other users (or with other Desire HD users) AFAICT.

The code is:

TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {     private int mCallCount = 0; // trying to investigate potential infinite loops      @Override     public void onInit(int status) {         if ((mCallCount % 100) == 1) {             // report this         }         mCallCount++;     } }); 

Anyone any ideas?

EDIT: I have also tried calling the shutdown() method (the first time multiple listener calls are detected) but this doesn't seem to help.

like image 941
Mark Avatar asked Jan 27 '11 16:01

Mark


1 Answers

Maybe you should get around it with your own intermediary method, for example:

private long lastCall = 0; private long deepBreath = 5*1000; //5 seconds private boolean hasRested;  TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {      @Override      public void onInit(int status) {          long thisCall = Calendar.getInstance().getTimeInMillis();         intermediaryMethod(status, thisCall);     }  });   //new method public void intermediaryMethod(int status, long thisCall) {     hasRested = (thisCall-lastCall)>=deepBreath;     if (hasRested) {         lastCall = thisCall;         //do something about 'status'     } } 
like image 106
Ozzy Avatar answered Sep 17 '22 02:09

Ozzy