Android text for speech initializes very slowly

My application is used by people with impaired vision, so it is highly dependent on text to speech. The application accesses the API and reads the load (using android.speech.tts.TextToSpeech) some relevant information to the user.

Everything works well, except that I noticed that sometimes initializing text to speech takes 10 seconds or more and is the main bottleneck of my application.

I was wondering if anyone has any ideas on how I can optimize my code to mitigate this problem.

First, my application launches a TTS data validation operation.

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, the text-to-speech is either simply initialized (this almost always happens), or the text-to-speech is installed on the device (very rarely).

  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 calls the API call and has a few lines like this:

  mTts.speak("<Useful output here>", TextToSpeech.QUEUE_FLUSH, null); 

Thanks for the help!

+7
android text-to-speech google-text-to-speech
source share
1 answer

A little late, but I would say if this just happens on the device. Other things with higher priority, taking CPU time. I think that a blind person will not need many applications on this device. Also consider the AutoPlay application. to automatically launch your application.

+1
source share

All Articles