8

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!

1

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.