我正在创建一个用户界面,并希望设备在到达指定位置(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);
}
我希望设备在完成任务后说"享受你的饭菜"。
我认为您在初始化实例时遇到一些问题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.");
}
});
这也可以帮助您检查语言是否可用。