title: Toggle TextToSpeech on and off using a togglebutton?
body: <p>So i have an app connected to firebase. The app retrieves data(a string) from firebase into a text view and then the TextToSpeech feature reads the text out(not from the textView but it itself retrieves the same data from firebase real-time database). I have used onDataChange() meathod so the texttospeech feature reads the text out as soon as any change in the data occurs on firebase, and not on the click of any button. Now i want to place a toggle button in my app and use it to either turn the tts feature on or off but i cant get it to work. When the toggle button  is off, i want the texttospeech feature to stop and when the button state is on, i want the texttospeech feature to turn back on.This is what ive tried:</p>
  
  <pre><code>  mtts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
          @Override
          public void onInit(int status) {
              if (status != TextToSpeech.ERROR){
                  mtts.setLanguage(Locale.US);    }else{
  
  
                  Toast.makeText(MainActivity.this, "Couldnt initialize speech function!", Toast.LENGTH_SHORT).show();
              }
  
          }
      }); mIvToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                          if (isChecked){
                              reff = FirebaseDatabase.getInstance().getReference().child("Match").child("Screen1");
                              reff.addValueEventListener(new ValueEventListener() {
                                  @Override
                                  public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
  
                                      String tts= dataSnapshot.getValue().toString();
                                      mtts.speak(tts, TextToSpeech.QUEUE_FLUSH, null);
  
  
                                  }
  
                                  @Override
                                  public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                  }
                              });
  
  
                          }else{
                              mtts.stop();
                              mtts.shutdown();
  
  
  
                          }
                      }
                  });
  </code></pre>
  
  <p>TIA !</p>