I was trying to converting text to speech
in API level 22. Unfortunately, it's not working below API level 23.
tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status!=TextToSpeech.ERROR)
{
tts.setLanguage(Locale.US);
}
}
});
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text=etxtText.getText().toString();
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
//1.0f is default speech rate, increase to high and decrease to lower
tts.setSpeechRate(1.0f);
}
});
}
@Override
protected void onPause() {
if (tts!=null)
{
//to stop speech
tts.stop();
tts.shutdown();
}
super.onPause();
}
It's working in upper version. But, not in API level 22. Is there possible way to run it in API level 22.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…