title: Text To Speech using Google Engine in Android
body: <p>I'm developing a simple application in Android, i have a problem with TextToSpeech.</p>
  
  <p>The application must pronounce the letters of the alphabet and numbers using TextToSpeech, but there's a problem, by default devices use PicoTTS I wish they were forced to use of the google tts engine.</p>
  
  <p>How i can do this ?</p>
  
  <p>My code:</p>
  
  <pre><code>@SuppressLint("NewApi")
  public class LearnAlphabet extends Activity {
   Button howto, number, alphabet;
   public TextToSpeech tts;
  
  
  
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.learn_number);
  
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0170a5")));
  
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new NumberFunction(this));
  
    final String locale = getApplicationContext().getResources().getConfiguration().locale.getLanguage();
  
  
  
    tts = new TextToSpeech(getApplicationContext(), 
     new TextToSpeech.OnInitListener() {
      @Override
      public void onInit(int status) {
       if(status != TextToSpeech.ERROR){      
  
      switch (locale.toString()) {
       case "it":
        tts.setLanguage(new Locale("it_IT"));
       break;
  
       case "en":
        tts.setLanguage(new Locale("en_US")); 
       break;
  
       case "es":
        tts.setLanguage(new Locale("es_ES"));
       break;
  
       case "de":
        tts.setLanguage(new Locale("de_NL"));
       break;
  
       case "ru":
        tts.setLanguage(new Locale("ru_RU"));
       break;
  
       default:
        tts.setLanguage(new Locale("en_US"));  
       break;
      }    
  
       }              
      }
    }); 
   }
  </code></pre>
  
  <p>and for each letter or number:</p>
  
  <pre><code>  tts.speak(getResources().getString(R.string.a), TextToSpeech.QUEUE_FLUSH, null);
  </code></pre>
  
  <p>**** EDIT ***** 
  Error if i set : 
  tts.setEngineByPackageName("com.google.android.tts")</p>
  
  <pre><code>12-11 15:52:04.954: E/AndroidRuntime(12203): FATAL EXCEPTION: main
  12-11 15:52:04.954: E/AndroidRuntime(12203): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.imparafacile/com.imparafacile.LearnAlphabet}: java.lang.NullPointerException
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread.access$600(ActivityThread.java:149)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.os.Looper.loop(Looper.java:137)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread.main(ActivityThread.java:5214)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at java.lang.reflect.Method.invoke(Method.java:525)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at dalvik.system.NativeStart.main(Native Method)
  12-11 15:52:04.954: E/AndroidRuntime(12203): Caused by: java.lang.NullPointerException
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at com.imparafacile.LearnAlphabet.onCreate(LearnAlphabet.java:47)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.Activity.performCreate(Activity.java:5133)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  12-11 15:52:04.954: E/AndroidRuntime(12203):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
  </code></pre>