0
cname = contactname.getText().toString();
tts.speak("Reciepient name is  " + cname, TextToSpeech.QUEUE_FLUSH, null);

Above code is working but below code does not speak the string value.

String ww = "Welcome";
tts.speak(ww, TextToSpeech.QUEUE_FLUSH, null);
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Ahsan
  • 19
  • 2
  • 8

2 Answers2

1

The TTS Engine can be temperamental, unless instead of null you need to add a HashMap which contains the utterance ID.

There are so many tutorials out there that show how to do this and even if your implementation doesn't require it right now, it's likely you'll need to know when the utterance is completed at some point in your future design.

The Android introduction is a good place to start.

Test different TTS engines, on different devices and OS versions - Many behave differently and expose problems that are not associated to your base code

brandall
  • 6,094
  • 4
  • 49
  • 103
0

I had the same problem. I fixed in this way:

    txt.setText("Hello"+" "+"World");
    tts.speak(txt, TextToSpeech.QUEUE_FLUSH, null);
Boris Karloff
  • 1,190
  • 12
  • 20