title: UtteranceProgressListener not working for Android TTS
body: <p>I am making an app that uses tts to synthesize wav files every time a broadcastreceiver is triggered. Im working on AndroidStudio (latest) and using API level 19 with min 15.</p>
  
  <p>I have a Service with a BroadcastListener. Every time the BroadcastListener onReceive method is executed, I use </p>
  
  <p><code>tts.synthesizeToFile(playing, null, storagePath + "/" + "tst.wav");</code></p>
  
  <p>The file is created successfully, but the onDone() method of the UtteranceProgressListener is never called.</p>
  
  <pre><code>public void onCreate() {
      super.onCreate();
  
      //Get TTS capabilities
      //TODO: Use TextToSpeech.Engine.ACTION_CHECK_TTS_DATA to check if tts is available
      tts = new TextToSpeech(PresenterService.this,
              new TextToSpeech.OnInitListener() {
                  @Override
                  public void onInit(int status) {
  
                      //If the TTS engine was started successfully
  
                      if (status != TextToSpeech.ERROR) {
  
                          tts.setLanguage(Locale.US);
                          tts.setPitch(PRESENTER_PITCH);
                          tts.setSpeechRate(PRESENTER_RATE);
                      }
  
                  }
              });
  
      tts.setOnUtteranceProgressListener(new TtsUtteranceListener());
  
  
  
      IntentFilter filter = new IntentFilter();
      filter.addAction("xxxxxxxxxxxxxxxxxx");
  
      mReceiver = new TrackChangedReceiver(tts);
      registerReceiver(mReceiver, filter);
  
  }
  </code></pre>
  
  <p>And the TtsUtteranceListener class:</p>
  
  <pre><code>public class TtsUtteranceListener extends UtteranceProgressListener {
  
      @Override
      public void onDone(String utteranceId) {
          Log.d("TtsUtteranceListener", "utterance Done: " + utteranceId);
      }
  
      @Override
      public void onStart(String utteranceId) {
          Log.d("TtsUtteranceListener", "utterance Start: " + utteranceId);
      }
  
      @Override
      public void onError(String utteranceId) {
          Log.d("TtsUtteranceListener", "utterance Error: " + utteranceId);
      }
  }
  </code></pre>
  
  <p>The method on the listener:</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
  
      if (action != null) {
          if (action.equalsIgnoreCase("xxxxxxxxxxxxxxxxx")) {
              String playing = "test string";
              tts.synthesizeToFile(playing, null, storagePath + "/" + "tst.wav");
          }
      }
  }
  </code></pre>
  
  <p>I'm using AndroidStudio, and with the debug mode I can see that the mUtteranceProgressListener of the tts object has some object reference:</p>
  
  <pre><code>com.example.android.ttstest.TtsUtteranceListener@41eaf8d8
  </code></pre>
  
  <p>but the methods of the listener are never called. The  Log.d() calls never work and any breakpoints there are never triggered. </p>
  
  <p>I also tried by declaring the UtteranceProgressListener as an anonymous class when calling </p>
  
  <pre><code>tts.setOnUtteranceProgressListener(new UtteranceProgressListener(){...});
  </code></pre>
  
  <p>but same thing...</p>
  
  <p>Can someone point me in what am I doing wrong?</p>