textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) {
Toast.makeText(LoginedActivity.this, "暂不支持该语言", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) {
Toast.makeText(LoginedActivity.this, "暂不支持该语言", Toast.LENGTH_SHORT).show();
}
}
}
});
button(new View.OnClickListener() {
@Override
public void onClick(View v) {
textToSpeech.setSpeechRate(1);//语速
textToSpeech.speak("查询", TextToSpeech.QUEUE_ADD, null, "speech");//语音播报内容
}
});