SpeechToText and launch intent ACTION_CHECK_TTS_DATA

I implemented TextToSpeech integration, as stated in this blog post . After I added it to my program, it now intervenes in my other intent s.

For example:

  • List item
  • The user launches the application
  • User triggers download activity
  • The user selects the file to upload, and the activity returns the fileanme to upload in the intent
  • The main activity begins, and she realizes that she needs to download the file name in order for it to start.
  • The TTS check must be done, so I run the ACTION_CHECK_TTS_DATA intent
  • This pauses the main action again, and the download process is interrupted.
  • When the TTS checks, the download never occurred.

When do I need this TTS check? Can I just do this once when the application starts? This causes my application to load slowly. I would like this loading to be done in a separate thread, if possible.

+5
android text-to-speech
source share
1 answer

Check once. Once the data is installed, it is very unlikely that the user will ever need to do this again. Once the data is installed, the user will not be able to delete it, even if they want to.

Also, do not use ACTION_CHECK_TTS_DATA Intent, which is inconvenient to use.

Instead, follow these steps:

  • Create TextToSpeech
  • OnInit, check isLanguageAvailable () if so, your application is configured. if not, send ACTION_INSTALL_TTS_DATA

Here is the code that initializes TextToSpeech as I suggest. As a bonus, it also sets the language.

 public class DemoCreateTTS { private static final String TAG = "DemoCreateTTS"; private TextToSpeech tts; public void createTextToSpeech(final Context context, final Locale locale) { tts = new TextToSpeech(context, new OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { Locale defaultOrPassedIn = locale; if (locale == null) { defaultOrPassedIn = Locale.getDefault(); } // check if language is available switch (tts.isLanguageAvailable(defaultOrPassedIn)) { case TextToSpeech.LANG_AVAILABLE: case TextToSpeech.LANG_COUNTRY_AVAILABLE: case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: Log.d(TAG, "SUPPORTED"); tts.setLanguage(locale); //pass the tts back to the main //activity for use break; case TextToSpeech.LANG_MISSING_DATA: Log.d(TAG, "MISSING_DATA"); Log.d(TAG, "require data..."); Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); context.startActivity(installIntent); break; case TextToSpeech.LANG_NOT_SUPPORTED: Log.d(TAG, "NOT SUPPORTED"); break; } } } }); } } 
+8
source share

All Articles