我正在创建一个用户界面,并希望设备到达指定位置(onFinished
)时说“享受美食”。
@Override
public void onFinished(PeanutPath runningPath) {
log.d(TAG, "onFinished" + ", targetId:" + runningPath.getDestinationId());
tvPilotStatus.setText("【Target:" + runningPath.getDestinationId() + "】" + "Finished");
tts.speak("Enjoy your meal", TextToSpeech.QUEUE_FLUSH, null);
}
我希望设备在完成任务后会说“享受一顿饭”。
答案 0 :(得分:0)
我认为您在初始化TextToSpeech
实例时遇到一些问题。您应该像这样初始化它:
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
int ttsLang = tts.setLanguage(Locale.US);
if (ttsLang == TextToSpeech.LANG_MISSING_DATA
|| ttsLang == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "The Language is not supported!");
} else {
Log.i("TTS", "Language Supported.");
}
Log.i("TTS", "Initialization success.");
}
});
这还可以帮助您检查该语言是否可用。