2017-06-28 8 views
0

Je dois démarrer une animation pouvant être dessinée lorsque mon texte à partir de la parole commence et arrêter celui-ci lorsque le texte à la parole est terminée, mais je ne peux pas arrêter l'animation.Faire quelque chose lorsque la synthèse vocale est terminée

code:

tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { 

     @Override 
     public void onInit(int status) { 
      if (status == TextToSpeech.SUCCESS) { 
       int result = tts.setLanguage(Locale.US); 

       if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { 
        Log.e("TTS", "This Language is not supported"); 
       } 

      } else { 
       Log.e("TTS", "Initilization Failed!"); 
      } 
     } 
    }); 

private void speak(String text){ 
    animation.start(); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null); 

    }else{ 
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 

    } 
} 

et ici mon animationdrawable xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/selected" android:oneshot="false" > 

<item android:drawable="@drawable/face_1a_mini" android:duration="250" /> 

<item android:drawable="@drawable/face_1b_mini" android:duration="250" /> 
<item android:drawable="@drawable/face_1c_mini" android:duration="250" /> 

<item android:drawable="@drawable/face_1d_mini" android:duration="250" /> 
</animation-list> 
+3

Salut et bienvenue à débordement de la pile, s'il vous plaît prendre le temps de passer par la [bienvenue tournée] (https://stackoverflow.com/tour) de connaître votre chemin ici (et aussi pour gagner votre premier insigne), lisez comment créer un [exemple minimal, complet et vérifiable] (https://stackoverflow.com/help/mcve) et également [Comment poser de bonnes questions] (https://stackoverflow.com/help/ Comment demander) afin d'augmenter vos chances d'obtenir des commentaires et des réponses utiles. – DarkCygnus

+0

Copie possible de [Comment savoir quand TTS est fini?] (Https://stackoverflow.com/questions/4658376/how-to-know-when-tts-is-finished) –

Répondre

0

Vous devez envelopper avec while(tts.isSpeaking())

exemple:

while(tts.isSpeaking()) 
      { 
       Animation animation1 = 
       AnimationUtils.loadAnimation(this,R.anim.fadein); 
       view.startAnimation(animation1); 
      } 
0

démarrer votre animat ion au début de l'énoncé et s'arrêter lorsque l'énoncé est fait.

t1 = new TextToSpeech(this, new TextToSpeech.OnInitListener() { 
       @Override 
       public void onInit(int status) { 
        if (status != TextToSpeech.ERROR) { 
         t1.setLanguage(Locale.UK); 
        t1.setOnUtteranceProgressListener(new UtteranceProgressListener() { 
         @Override 
         public void onStart(String utteranceId) { 

         } 

         @Override 
         public void onDone(String utteranceId) { 
          if(utteranceId.equals("finish")){ 
           finish(); 
          } 
         } 

         @Override 
         public void onError(String utteranceId) { 

         } 
        }); 
         } 

       } 
      });