@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
init();
}
public void init() {
tts = new TextToSpeech(Game.this, new OnInitListener() {
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
speakout("Hello Gies");
}
}
});
}
public void speakout(String text) {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
tv2.setText("" + text);
}
@Override
protected void onPause() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onPause();
}
代码运行正常。我试图将文本转换为语音,但我无法找到想要的输出。请帮我解决问题。 在此先感谢。Text to Speech android not working
你是什么意思'找到所需的输出'?您还应该添加一个话语监听器 - 请参阅此答案中的链接http://stackoverflow.com/a/22642640/1256219 – brandall