title: UtteranceProgressListener Out of Sync
body: <p>Summary<br /></p>
  
  <ul>
  <li>List of utterances in an array</li>
  <li>Loop through array and call my method "sayThis" for each utterance</li>
  <li>UtteranceProgressListener is being called, and TTS works</li>
  <li>Calling of my method "sayThis" appears to be called at times prior to UtteranceProgressListener completing current utterance</li>
  </ul>
  
  <p>I believe the flow should be the following:<br /></p>
  
  <p>1) Call to method "sayThis", if voiceReady=true <br />
  2) TTS starts utterance and UtteranceProgressListener onStart called &amp; sets voiceReady to false<br />
  3) Call to method "sayThis" should not be called if voiceReady=false<br />
  4) UtteranceProgressListener onDone called when utterance if finished, voiceReady=true<br />
  5) Call to method "sayThis" can be called again, since voiceReady=true<br />
  6) Above should continue until utterance array had been looped through to completion<br /></p>
  
  <pre><code>    //Code snippet that loops through array and calls "sayThis" method
      //There are no errors
      while(arrayCounter &lt; utterances.size()) {
          if (voice.voiceReady == true) {
              voice.sayThis(utterances.get(arrayCounter), arrayCounter);
              arrayCounter++;
          }
      }
  
      //Code snippet that processes speech
      //There are no errors
      public void sayThis(String whatToSay, int utteranceID){
      Log.d(LOG_SOURCE, "sayThis method called: Utterance ID=" + utteranceID);
      voiceParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, Integer.toString(utteranceID));
      ttsVoice.speak(whatToSay, TextToSpeech.QUEUE_ADD, voiceParams);        
  }
  
      //Code snippet from the UtteranceProgressListener
      //You can see from the logs the methods are being called
      @Override
      public void onStart(String utteranceID) {
          voiceReady = false;
          Log.d(LOG_SOURCE, "(ttsUtteranceListener) UtteranceProgressListener onStart " +
                  "method called for utteranceID:" + utteranceID + ", voiceReady=false");
      }
  
      @Override
      public void onDone(String utteranceID) {
          voiceReady = true;
          Log.d(LOG_SOURCE, "(ttsUtteranceListener) UtteranceProgressListener onDone " +
                  "method called for utteranceID:" + utteranceID + ", voiceReady=true");
  </code></pre>
  
  <p>- Logcat would indicate this pattern isn't always followed as shown below:<br /></p>
  
  <pre><code>02-13 18:05:25.487: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=0
  02-13 18:05:25.490: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:0, voiceReady=false
  02-13 18:05:29.578: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:0, voiceReady=true
  02-13 18:05:29.578: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=1
  02-13 18:05:29.580: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:1, voiceReady=false
  02-13 18:05:33.107: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=2
  02-13 18:05:33.107: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:1, voiceReady=true
  02-13 18:05:33.109: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:2, voiceReady=false
  02-13 18:05:38.667: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=3
  02-13 18:05:38.667: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:2, voiceReady=true
  02-13 18:05:38.668: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=4
  02-13 18:05:38.669: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=5
  02-13 18:05:38.671: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:3, voiceReady=false
  02-13 18:05:45.411: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:3, voiceReady=true
  02-13 18:05:45.411: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:4, voiceReady=false
  02-13 18:05:49.966: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:4, voiceReady=true
  02-13 18:05:49.966: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:5, voiceReady=false
  02-13 18:05:54.198: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:5, voiceReady=true
  02-13 18:05:54.199: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=6
  02-13 18:05:54.202: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:6, voiceReady=false
  02-13 18:05:55.912: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:6, voiceReady=true
  02-13 18:05:55.912: D/LFS_TheVoice(10645): sayThis method called: Utterance ID=7
  02-13 18:05:55.914: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onStart method called for utteranceID:7, voiceReady=false
  02-13 18:05:56.765: D/LFS_TheVoice(10645): (ttsUtteranceListener) UtteranceProgressListener onDone method called for utteranceID:7, voiceReady=true
  </code></pre>
  
  <p>Any recommendation on how to sync the flow?  <br /><br />It's almost like the iteration through the array and calling the "sayThis" method happens faster than the UtteranceProgressListener can keep up with switching the true/false value of "voiceReady" boolean. <br /><br />This will cause flow control issues for me if I cannot accurate detect when each utterance has completed.</p>
  
  <p>Thanks<br />
  Michael</p>