In Android ---- How can we get a word that says in Text to Speech?

Does anyone help me with the text-to-speech tooltip?

My goal is to give a hint what word the device is reading.

Text for 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.

+4
source share
1 answer

You need to break the word with a word and highlight the specified word. E.g. if we take a sentence like "You did not type text":

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

You can do this using txtText.getText().toString().Split" "; to return an array of strings of words separated by a space. Then go through this array to find out which word is spoken, and select it in the TextView, for example,

+1
source

All Articles