title: Text to speech playing automatically
body: <p>I have a text to speech function in my android app that works to an onClick event, there is an issue  when the activity starts, the text to speech starts without clicking the button, is there a line of code I can put in to stop this happening, thank you.</p>
  
  <pre><code>package com.androidhive.texttospeech;
  
  import java.util.Locale;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.speech.tts.TextToSpeech;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class AndroidTextToSpeechActivity extends Activity implements
      TextToSpeech.OnInitListener {
  /** Called when the activity is first created. */
  
      private TextToSpeech tts;
      private Button button1;
      private TextView txtText;
  
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      tts = new TextToSpeech(this, this);
  
      button1 = (Button) findViewById(R.id.button1);
  
      txtText = (TextView) findViewById(R.id.txtText);
  
      // button on click event
      button1.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              speakOut();
          }
  
      });
   }
  
  @Override
  public void onDestroy() {
      // Don't forget to shutdown!
      if (tts != null) {
          tts.stop();
          tts.shutdown();
      }
      super.onDestroy();
   }
  
  @Override
  public void onInit(int status) {
      // TODO Auto-generated method stub
  
      if (status == TextToSpeech.SUCCESS) {
  
          int result = tts.setLanguage(Locale.US);
  
          // tts.setPitch(5); // set pitch level
  
          // tts.setSpeechRate(2); // set speech speed rate
  
          if (result == TextToSpeech.LANG_MISSING_DATA
                  || result == TextToSpeech.LANG_NOT_SUPPORTED) {
              Log.e("TTS", "Language is not supported");
          } else {
              button1.setEnabled(true);
              speakOut();
          }
  
      } else {
          Log.e("TTS", "Initilization Failed");
      }
  
      }
  
   private void speakOut() {
  
      String text = txtText.getText().toString();
  
      tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
     }
  }
  </code></pre>