title: Android Studio Text-to-Speech not working
body: <p>Ive watched tutorials and copied exactly but text to speech throws an error. Here is the code:</p>
  
  <pre><code>public void speak(String text){
      TextToSpeech text_to_speech;
      text_to_speech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
          @Override
          public void onInit(int status) {
              if (status == TextToSpeech.SUCCESS){
                  int result = text_to_speech.setLanguage(Locale.ENGLISH);
                  if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){
                      Log.e("TTS", "Language not supported");
                  } else {
                      text_to_speech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
                  }
              } else {
                  Log.e("TTS", "Failed");
              }
          }
      });
  }
  </code></pre>
  
  <p>The error is "the variable text_to_speech might not be initialized". </p>
  
  <p>UPDATE: the error only points to <code>int result = text_to_speech.setLanguage(Locale.ENGLISH);</code></p>