在 Android 中----我们如何获取在 Text to Speech 中说话的单词?

pat*_*tel 5 android google-text-to-speech

有没有人帮我在文本到语音中提供提示?

我的目标是提示设备正在读取哪个单词。

文本到语音我的代码如下:-

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);
Run Code Online (Sandbox Code Playgroud)

谢谢。

Moh*_*lah 1

您需要逐字分解它,并突出显示提到的单词。例如,如果我们采用“您尚未输入文本”这样的句子:

 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.*/

...
Run Code Online (Sandbox Code Playgroud)

txtText.getText().toString().Split" ";您可以通过使用返回由空格分隔的单词的字符串数组来完成此操作。然后循环遍历这个数组来知道说出的是哪个单词,并在 TextView 中突出显示它,例如