0

This is a case of a talking avatar, where the animation and the speech have to sync.

The following code is the onClick function that is invoked when the speak button is pressed.

    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            avatarSpeak.stop();
            tts1.setPitch(p1);
            tts1.setSpeechRate(sr1);
            String toSpeak = ed1.getText().toString();
            createAnim(toSpeak, sr1);
            lang = sp1.getSelectedItem().toString();
            if (lang.equals("US")) {
                System.out.print("Condition satisfied");
                tts1.setLanguage(Locale.US);
            } else if (lang.equals("UK"))
                tts1.setLanguage(Locale.UK);
            else if (lang.equals("Germany"))
                tts1.setLanguage(Locale.GERMANY);
            else if (lang.equals("Italy"))
                tts1.setLanguage(Locale.ITALY);
            else if (lang.equals("Japan"))
                tts1.setLanguage(Locale.JAPAN);
            else
                tts1.setLanguage(Locale.CHINA);

            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            tts1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                tts1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null, null);
            } else {
                tts1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
            }
            avatarSpeak.start();
        }
    });

As you can read the code avatarSpeak is the animationDrawable, that plays the animation for the speech. The animation is created, according to the text entered by the createAnim function, called in the code. The animation function is called, only after the speak function is invoked, to speak the words.

However, when the app is run for the first time, the animation plays first, and after a few seconds delay, the speech occurs. How can this occur, when the speech is invoked, before the animation.?

I could provide more data if required.

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92

0 Answers0