Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 651
patel Avatar asked Nov 13 '22 12:11

patel


1 Answers

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.

like image 84
Mohamed_AbdAllah Avatar answered Nov 15 '22 04:11

Mohamed_AbdAllah