I am developing android application in which I am using text to speech conversion.What I need when I open my application run text to speech conversion. After completion of t
Here is some code from here that helps you be backward compatible so you don't have to target 15.
private void setTtsListener()
{
final SpeechRecognizingAndSpeakingActivity callWithResult = this;
if (Build.VERSION.SDK_INT >= 15)
{
int listenerResult = tts.setOnUtteranceProgressListener(new UtteranceProgressListener()
{
@Override
public void onDone(String utteranceId)
{
callWithResult.onDone(utteranceId);
}
@Override
public void onError(String utteranceId)
{
callWithResult.onError(utteranceId);
}
@Override
public void onStart(String utteranceId)
{
callWithResult.onStart(utteranceId);
}
});
if (listenerResult != TextToSpeech.SUCCESS)
{
Log.e(TAG, "failed to add utterance progress listener");
}
}
else
{
int listenerResult = tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener()
{
@Override
public void onUtteranceCompleted(String utteranceId)
{
callWithResult.onDone(utteranceId);
}
});
if (listenerResult != TextToSpeech.SUCCESS)
{
Log.e(TAG, "failed to add utterance completed listener");
}
}
}