1

Im having a odd Problem with the TTS engine and I cant figure out why / where is my mistake. Is searched for hours for a solution but without any mentionable result.

When I am using this API Demo code everything is working well and I can hear for all installed languages the voice.

But when I am checking by this method I am getting CHECK_VOICE_DATA_FAIL as a return code for custom TTS engines (which I need for all necessay languages, Standard google is not enough).

What am I missing here? How can I check the availabillity of the TTS engines? I know that this is not necessarily a code problem but, for other Programms this seems to be working.

I installed some other apps from the SVox Website and these seem to work on all my devices, while the code below fails.

As an example, TalkToMeClassic is checking the availlability of the Engine and it is working.

What is done different here?

Here is my excact code (which is a copy of the article):

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, 0x99);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0x99) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // success, create the TTS instance
            mTts = new TextToSpeech(this, this);
        } else {
            Log.e("TTS","Missing Data:" + resultCode );
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }
}
KarlKarlsom
  • 5,868
  • 4
  • 29
  • 36
  • Are those engines you developed? This code only checks the default engine, and if it is not implemented to handle the check, you might get strange results. Does it work if ignore the result of this check (i.e., do you get speech audio)? – Nikolay Elenkov Jun 21 '12 at 07:21

1 Answers1

3

Unfortunately, initializing TextToSpeech reliably is complicated, asynchronous, and confusing.

Why is your code checking 0x99???

You actually don't need to use the ACTION_CHECK_TTS_DATA Intent to check for language availability, use TextToSpeech.isLanguageAvailable instead.

So here is a helper class that does it. The code in that library will help you get started. It can be as easy as just extending this class.

Or you can read about the details in this book.

gregm
  • 12,019
  • 7
  • 56
  • 78
  • Thanks. The helper class is very usefull. But one thing is still unclear to me: Is the Intent obsolete and should only be used for older versions? – KarlKarlsom Jun 24 '12 at 07:03
  • The Intent is not obsolete and provides other info about the TTS engine. I just believe it is not the most convenient way to check for language data. – gregm Jun 25 '12 at 08:36