我的应用程序中有文字转语音功能,如果您点击文字,设备会读出该文字。但是,当您点击它时,它会读出代码,而不是消息中包含的内容。
功能如下:
private TextToSpeech t1;
在我的onCreate()
中:
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
以及我的消息中
protected void populateView(View v, Message model, int position) {
TextView messageText
messageText = v.findViewById(R.id.message_text);
messageText.setText(model.getMessageText());
final String msgText = messageText.toString();
messageTextRight.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
t1.speak(msgText.toString(), TextToSpeech.QUEUE_FLUSH, null);
return true;
}
});
}