My application is used by people who are visually impaired so it relies heavily on text to speech. The application makes a call to an API and reads out load (using android.speech.tts.TextToSpeech) some relevant information to the user.
Everything works well, except I have noticed that sometimes the initialization of text to speech takes 10 seconds or more and is the major bottleneck of my application.
I was wondering if anyone had any ideas about how I could optimize my code to mitigate this problem.
First, my application starts an activity to check the TTS Data.
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
Then, this method is called with the result of the activity. Depending on the result, text to speech is either just initialized (this almost always occurs) or text to speech is installed on the device (very rare).
private TextToSpeech mTts;
@Override
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
Finally, when all this completes my application makes a call to an API and has several lines like this:
mTts.speak("<Useful output here>", TextToSpeech.QUEUE_FLUSH, null);
Thank you for the help!
Tap the Settings icon . Scroll down and tap Accessibility. Scroll down and tap Text-to-speech output. Adjust the sliders for Speech Rate and Pitch.
A bit late in the day but I would say, is it simply whats going on in the device. Other things with higher priority taking processor time. I think that a blind person would not need many apps on there device. Also consider the Auto Start app. to automatically start your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With