I am creating an application that uses tts to synthesize wav files every time the translation starts. Im runs on AndroidStudio (the latter) and uses API level 19 with min 15.
I have a service with a BroadcastListener. Every time the BroadcastListener onReceive method is executed, I use
tts.synthesizeToFile(playing, null, storagePath + "/" + "tst.wav");
The file was created successfully, but the onDone () method of the UtteranceProgressListener object is never called.
public void onCreate() {
super.onCreate();
tts = new TextToSpeech(PresenterService.this,
new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
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);
}
And the TtsUtteranceListener class:
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);
}
}
Listener method:
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");
}
}
}
I use AndroidStudio, and in debug mode, I see that the tts object's mUtteranceProgressListener has some object reference:
com.example.android.ttstest.TtsUtteranceListener@41eaf8d8
but listener methods are never called. Log.d () calls never work, and any breakpoints never start.
UtteranceProgressListener
tts.setOnUtteranceProgressListener(new UtteranceProgressListener(){...});
...
- , ?