我需要通知用户语音离开路线时。我不能使语音公告说“正在重新计算”。
我尝试创建了SpeechAnnouncement,甚至尝试创建ssml标签,但无济于事。
navigationView.retrieveMapboxNavigation().addOffRouteListener(new OffRouteListener() {
boolean isOffRouteAnnounced = false;
@Override
public void userOffRoute(Location location) {
if (!isOffRouteAnnounced) {
if (PreferencesManager.getInstance().getLanguage().equals("hu")) {
saySomething("Újratervezés");
} else {
willVoice(SpeechAnnouncement.builder().announcement("Recalculating").ssmlAnnouncement("<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Recalculating</prosody></amazon:effect></speak>").build());
}
isOffRouteAnnounced = true;
} else {
//handle the multiple rerouting requests, say it only once in 5 seconds
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
isOffRouteAnnounced = false;
}
}, 5000);
}
}
});
@Override
public SpeechAnnouncement willVoice(SpeechAnnouncement speechAnnouncement) {
if (PreferencesManager.getInstance().getLanguage().equals("hu")) {
saySomething(TranslatorUtil.getTranslationWithSeparator(speechAnnouncement.announcement().toLowerCase()));
return null;
} else {
return speechAnnouncement;
}
}
预期结果: -当offRoute检测触发时,语音会说“正在重新计算”。 实际结果: -会触发offRoute检测,但是willVoice什么也没说。