OnUtteranceCompletedListener を使用して、TTS が話し終わったことを検出していますが、OnUttereanceCompleted が呼び出されることはありません。HashMap の前に onInit でリスナーが作成されるため、何が問題なのかわかりません。何か案が?
public class TTSActivity extends Activity implements TextToSpeech.OnInitListener, OnUtteranceCompletedListener
{
private TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tts_layout);
tts = new TextToSpeech(this, this);
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
@Override
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
tts.setOnUtteranceCompletedListener(this);
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut()
{
HashMap<String, String> myHashAlarm = new HashMap<String, String>();
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "FINISHED PLAYING");
tts.speak("Some text.", TextToSpeech.QUEUE_FLUSH, myHashAlarm);
}
@Override
public void onUtteranceCompleted(String utteranceId)
{
if(utteranceId=="FINISHED PLAYING")
{
Log.i("TTS", "Called"); //never called
}
}