6

Any one help me for Provide hint in Text to Speech?

My aim is to provide hint which word is reading by devices.

Text to Speech My code is below :-

TextToSpeech tts = new TextToSpeech(this,this);
if (txtText.getText().toString().length() == 0) 
        tts.speak("You haven't typed text", TextToSpeech.QUEUE_FLUSH, null);
     else
        tts.speak(txtText.getText().toString(), TextToSpeech.QUEUE_FLUSH,null);

Thanks.

patel
  • 830
  • 1
  • 11
  • 26

1 Answers1

1

You need to break it down, word by word, and highlight the mentioned word. For e.g. if we take a sentence like "You haven't typed text":

 tts.speak("You", TextToSpeech.QUEUE_FLUSH, null);
/*Change size or color of "You" in your TextView for e.g.*/
 tts.speak("haven't", TextToSpeech.QUEUE_FLUSH, null);
/*Change size or color of "haven't" in your TextView for e.g.*/
 tts.speak("typed", TextToSpeech.QUEUE_FLUSH, null);
/*Change size or color of "typed" in your TextView for e.g.*/

...

You can do this by using txtText.getText().toString().Split" "; to return a String Array of the words separated by space. Then loop through this Array to know which word is spoken and highlight it in the TextView like this for e.g.

Community
  • 1
  • 1
Mohamed_AbdAllah
  • 5,311
  • 3
  • 28
  • 47
  • Thanks. I used TextToSpeech.QUEUE_ADD but My Problem is not Solved because of TextToSpeech.QUEUE_ADD take few milliseconds and Text is bold immediate. – patel Feb 04 '13 at 13:41
  • Try to adjust it with `Thread.Sleep(/*few millis*/);` in setting your Text Bold – Mohamed_AbdAllah Feb 04 '13 at 14:19
  • Please use below link http://stackoverflow.com/questions/14701602/in-android-how-can-we-provide-hint-which-word-is-speaking-in-text-to-speech(But it not Speaking well). – patel Feb 05 '13 at 12:14