patel
patel

Reputation: 850

In Android----How can we get word which is speaking in Text to Speech?

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.

Upvotes: 6

Views: 3160

Answers (1)

Mohamed_AbdAllah
Mohamed_AbdAllah

Reputation: 5322

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.

Upvotes: 1

Related Questions