Search code examples
androidtext-to-speech

TTS - CHECK_VOICE_DATA_FAIL - Check engine availlable


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);
        }
    }
}

Solution

  • 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.